Tag Archives: linux change timezone to utc

How to change timezone in Linux server (RedHat, CentOS, Ubuntu)

Learn how to change timezone in the Linux server. Understand timezone files location, configuration files, and way to change timezone using them.

Timezone configuration

This article is a beginner’s guide to change the timezone of the Linux server. Timezone is crucial for the server since the server’s native time is displayed according to timezone.

Server’s current timezone can be checked using simple date command

root@kerneltalks # date
Tue Nov  7 17:23:54 UTC 2017

In the above output, UTC (Coordinated Universal Time) is your server’s timezone. If you want to change it to match your region or application’s user’s timezone there are three ways you can do it.

If you want to change the timezone without much hassle and without messing around system files directly jump to datetimectl command option below.

How to change timezone in Linux using /etc/localtime file

/etc/localtime is the file used by the kernel to determine the timezone. If you check your current file, its a soft link to respective timezone file in /usr/share/zoneinfo directory.

root@kerneltalks # ll /etc/localtime
lrwxrwxrwx. 1 root root 25 Jul 11 16:06 /etc/localtime -> ../usr/share/zoneinfo/UTC

root@kerneltalks # ls -lrt /usr/share/zoneinfo/
total 284
-rw-r--r--.  1 root root 17722 Dec  5  2016 zone1970.tab
-rw-r--r--.  1 root root 19153 Feb 10  2017 zone.tab
-rw-r--r--.  1 root root  4445 Feb 28  2017 iso3166.tab
-rw-r--r--.  6 root root   118 Mar 21  2017 Zulu
-rw-r--r--.  2 root root  1518 Mar 21  2017 W-SU
-rw-r--r--.  1 root root  1873 Mar 21  2017 WET
-rw-r--r--.  6 root root   118 Mar 21  2017 UTC
-rw-r--r--.  6 root root   118 Mar 21  2017 Universal
-rw-r--r--.  2 root root   118 Mar 21  2017 UCT
-rw-r--r--.  3 root root  2126 Mar 21  2017 Turkey
-rw-r--r--.  2 root root   384 Mar 21  2017 Singapore
-rw-r--r--.  2 root root   517 Mar 21  2017 ROK
-rw-r--r--.  2 root root   764 Mar 21  2017 ROC
-rw-r--r--.  1 root root  2294 Mar 21  2017 PST8PDT
-rw-r--r--.  5 root root   388 Mar 21  2017 PRC
-rw-r--r--.  3 root root  3519 Mar 21  2017 posixrules
-rw-r--r--.  2 root root  3439 Mar 21  2017 Portugal
-rw-r--r--.  2 root root  2679 Mar 21  2017 Poland
-rw-r--r--.  2 root root  2047 Mar 21  2017 NZ-CHAT
-rw-r--r--.  4 root root  2434 Mar 21  2017 NZ
-rw-r--r--.  4 root root  2427 Mar 21  2017 Navajo
-rw-r--r--.  1 root root  2294 Mar 21  2017 MST7MDT
-rw-r--r--.  1 root root   118 Mar 21  2017 MST
-rw-r--r--.  1 root root  2102 Mar 21  2017 MET
-rw-r--r--.  2 root root   641 Mar 21  2017 Libya
-rw-r--r--.  2 root root   219 Mar 21  2017 Kwajalein
-rw-r--r--.  2 root root   292 Mar 21  2017 Japan
-rw-r--r--.  2 root root   481 Mar 21  2017 Jamaica
-rw-r--r--.  3 root root  8981 Mar 21  2017 Israel
-rw-r--r--.  2 root root  1690 Mar 21  2017 Iran
-rw-r--r--.  2 root root  1174 Mar 21  2017 Iceland
-rw-r--r--.  1 root root   119 Mar 21  2017 HST
-rw-r--r--.  2 root root  1175 Mar 21  2017 Hongkong
-rw-r--r--. 10 root root   118 Mar 21  2017 Greenwich
-rw-r--r--. 10 root root   118 Mar 21  2017 GMT+0
-rw-r--r--. 10 root root   118 Mar 21  2017 GMT-0
-rw-r--r--. 10 root root   118 Mar 21  2017 GMT0
-rw-r--r--. 10 root root   118 Mar 21  2017 GMT
-rw-r--r--.  7 root root  3661 Mar 21  2017 GB-Eire
-rw-r--r--.  7 root root  3661 Mar 21  2017 GB
-rw-r--r--.  1 root root  2294 Mar 21  2017 EST5EDT
-rw-r--r--.  1 root root   118 Mar 21  2017 EST
-rw-r--r--.  2 root root  3533 Mar 21  2017 Eire
-rw-r--r--.  2 root root  1946 Mar 21  2017 Egypt
-rw-r--r--.  1 root root  1876 Mar 21  2017 EET
-rw-r--r--.  2 root root  2411 Mar 21  2017 Cuba
-rw-r--r--.  1 root root  2294 Mar 21  2017 CST6CDT
-rw-r--r--.  1 root root  2102 Mar 21  2017 CET
drwxr-xr-x.  2 root root   176 Jul 11 15:57 Indian
drwxr-xr-x.  2 root root  4096 Jul 11 15:57 Africa
drwxr-xr-x.  2 root root    53 Jul 11 15:57 Mexico
drwxr-xr-x.  2 root root    59 Jul 11 15:57 Brazil
drwxr-xr-x.  6 root root  8192 Jul 11 15:57 America
drwxr-xr-x.  2 root root   161 Jul 11 15:57 Canada
drwxr-xr-x.  2 root root   187 Jul 11 15:57 Antarctica
drwxr-xr-x.  2 root root    26 Jul 11 15:57 Arctic
drwxr-xr-x.  2 root root  4096 Jul 11 15:57 Asia
drwxr-xr-x.  2 root root   196 Jul 11 15:57 Atlantic
drwxr-xr-x.  2 root root  4096 Jul 11 15:57 Australia
drwxr-xr-x.  2 root root    45 Jul 11 15:57 Chile
drwxr-xr-x.  2 root root  4096 Jul 11 15:57 Etc
drwxr-xr-x.  2 root root  4096 Jul 11 15:57 Europe
drwxr-xr-x.  2 root root   216 Jul 11 15:57 US
drwxr-xr-x.  2 root root  4096 Jul 11 15:57 Pacific
drwxr-xr-x. 18 root root  4096 Jul 11 15:57 posix
drwxr-xr-x. 18 root root  4096 Jul 11 15:57 right

Since our test server’s timezone is UTC, you can see /etc/localtime is a soft link to /usr/share/zoneinfo/UTC. To change the timezone delete existing /etc/localtime file and create a new one with a link to the desired timezone file.

root@kerneltalks #  rm /etc/localtime
rm: remove symbolic link ‘/etc/localtime’? y

root@kerneltalks # ln -s /usr/share/zoneinfo/US/Eastern /etc/localtime

root@kerneltalks # date
Tue Nov  7 12:32:19 EST 2017

You can see we have changed timezone to EST by linking new localtime file to appropriate zone file under /usr/share/zoneinfo

How to change timezone using shell variable TZ

Another way to change the timezone is to use shell variable TZ. You can do it with single line command as below :

root@kerneltalks # export TZ=Asia/Singapore

root@kerneltalks # date
Wed Nov  8 01:36:15 +08 2017

I exported the timezone variable TZ for Singapore timezone. Check the date command output. Timezone has been set to +08 which means UTC+08:00 i.e. SGT (Singapore Timezone)

But remember, this timezone setting will be available for current shell only from where you are exporting this TZ variable.

How to change timezone using /etc/timezone file

The third way to change timezone is through the use of /etc/timezone file. This is available in some distro like Ubuntu. The content of the file will be the timezone name you want to set.

root@kerneltalks # cat /etc/timezone
Etc/UTC

root@kerneltalks # date
Tue Nov  7 17:50:50 UTC 2017

You have to export the timezone variable TZ as well along with a change in /etc/timezone file. And then you can see timezone change in effect.

Change timezone using timedatectl command

You can use timedatectl command to safely change timezone when you don’t want to deal with system files and fear of messing them up.

timedatectl command used to display current timezone, list available timezones, and change timezone on the server. We have this dedicated article on timedatectl to learn this command in detail.

To change timezone of server, use timedatectl with set-timezone argument and its value.

root@kerneltalks # timedatectl set-timezone Africa/Malabo
root@kerneltalks # date
Wed Nov 15 16:59:23 WAT 2017

In the output, you can see we have changed the timezone of the server to the WAT timezone.