How to Check and Set Timezone in Ubuntu

To Check and Set Timezone in Ubuntu

In this article we going to show how to check and set Timezone in simple way on Ubuntu machine. It is necessary to ensure and maintain an accurate log time-stamps in distributing systems.


To Check Timezone

First try a traditional command " date" to check the Timezone.

root@linuxhelp:~# date
Tue Nov 15 19:50:21 IST 2016

Use another command ' timedatectl' .

root@linuxhelp:~# timedatectl
Local time: Tue 2016-11-15 19:51:23 IST
Universal time: Tue 2016-11-15 14:21:23 UTC
RTC time: Tue 2016-11-15 14:21:23
Time zone: Asia/Kolkata (IST, +0530)
Network time on: yes
NTP synchronized: yes
RTC in local TZ: no

You can also use timedatectl with grep command.

root@linuxhelp:~# timedatectl | grep " Time zone" 
Time zone: Asia/Kolkata (IST, +0530)

Another simple method to check the timezone is using " cat" command.

root@linuxhelp:~# cat /etc/timezone
Asia/Kolkata

The strings command also displays the timezone.

root@linuxhelp:~# strings /etc/localtime | tail -n 1
IST-5:30

Move to the zoneinfo location and execute below command to check timezone in different way.

root@linuxhelp:~# cd /usr/share/zoneinfo
root@linuxhelp:/usr/share/zoneinfo# find * -type f -exec sh -c " diff -q /etc/localtime ' {}'  >  /dev/null & &  echo {}"   
Asia/Calcutta


To Set Timezone

Run the below command to set the time zone.

root@linuxhelp:~# dpkg-reconfigure tzdata

Select your continent.

Select your city.

After selecting the timezone, it displays the output as shown below,

Current default time zone: ' Asia/Kolkata' 
Local time is now: Tue Nov 15 19:58:25 IST 2016.
Universal Time is now: Tue Nov 15 14:28:25 UTC 2016.

Also use timedatectl command to set timezone.

root@linuxhelp:~# timedatectl set-timezone Asia/Kolkata

Once the timezone is set, check and verify your settings with the following command.

root@linuxhelp:~# timedatectl
Local time: Tue 2016-11-15 20:00:07 IST
Universal time: Tue 2016-11-15 14:30:07 UTC
RTC time: Tue 2016-11-15 14:30:08
Time zone: Asia/Kolkata (IST, +0530)
Network time on: yes
NTP synchronized: yes
RTC in local TZ: no

FAQ
Q
How to check, that what time zone has already enrolled?
A
For attaining the default time zone set on your machine use #timedatectl | grep " Time zone".
Q
How to set the timezone for the particular region via command line?
A
In order to set time for Asia/Kolkata set as follows # timedatectl set-timezone Asia/Kolkata.
Q
How to list out all valid Timezones present?
A
Please execute the below command
# timedatectl list-timezones
Q
How to change Ubuntu server's date and time via cli?
A
Please execute the below command
# date "30 Sep 2015 4:43:42"
Q
I have executed the command date "30 Sep 2015 4:43:42" which simply shows date and time?
A
Use " # hwclock --show" to verify the stated issue.