How To Change Timezone on a CentOS 6 and 7

Changing timezone in CentOS/Redhat 7 is now different from the previous CentOS/Redhat versions. This howto shows how to change the timezone in CentOS/RedHat 7 and previous versions.

Change TimeZone in CentOS/RedHat 7

List all available timezones

To find list of all available time zones, run:

[root@server yum]# timedatectl list-timezones

A portion of the sample output is as shown below:

[root@infra-1 yum]# timedatectl list-timezones

Set the timezone

Now that we know what the names of the timezones are, we can now set the timezone. For example from the above command we want to set timezone to Europe/Madrid:

[root@server yum]# timedatectl set-timezone Europe/Madrid
The timedatectl command simply really just updates the symlink /etc/localtime as shown below.
[root@server ]# ls -al /etc/localtime
lrwxrwxrwx. 1 root root 35 May  1  2016 /etc/localtime -> ../usr/share/zoneinfo/Europe/Madrid

Change or Set timezone in CentOS/RedHat 6.x

Unlike in the latest CentOS/RedHat we do not have a timedatectl command. Instead we simply have an /etc/localtime symlink to a file in /usr/share/zoneinfo. So to change timezone , you must first find the timezone file in /usr/share/zoneinfo.

Find the timezone file

The following example gives you an idea of how to find the timezone file:

root@server yum]# cd /usr/share/zoneinfo/
[root@server zoneinfo]# ls
Africa      Arctic    Australia  CST6CDT  Cuba  EST5EDT  Etc     GB-Eire  GMT-0      HST       Indian  Jamaica    Libya  MST7MDT  NZ-CHAT  PST8PDT  Portugal  Singapore  US         W-SU  right America     Asia      Brazil     Canada   EET   Egypt    Europe  GMT      GMT0       Hongkong  Iran    Japan      MET    Mexico   Navajo   Pacific  ROC       Turkey     UTC        WET   posix Antarctica  Atlantic  CET        Chile    EST   Eire     GB      GMT+0    Greenwich  Iceland   Israel  Kwajalein  MST    NZ       PRC      Poland   ROK       UCT        Universal  Zulu  posixrules
[root@server zoneinfo]#
Note that /usr/share/zoneinfo as shown above also have subdirectories. So if you do not recognise a usable timezone file, dig down into the directories. For example, the file /usr/share/zoneinfo/America/New_York represents time zone for New York.

Symlink /etc/localtime to the timezone file.

For example lets say we have decided we want to share our server to America/New_York and the timezone file is /usr/share/zoneinfo/America/New_York.

So first remove the /etc/timezone

root@server yum]# rm /etc/localtime

Follow that with creating the symlink:

root@server yum]# ln -s /usr/share/zoneinfo/America/New_York /etc/localtime