
By default, the timezone on CentOS set at the time of installation. To change timezone in CentOS is easy and straight forward. In this guide, we will show you how to change timezone on CentOS 7.
Prerequisites
You should logged in as a user with sudo privileges.
Get Current Timezone
You can get current timezone by simply issuing timedatectl
command. Run below command:
timedatectl
It will show output as below:
Local time: Thu 2019-04-25 04:20:54 UTC
Universal time: Thu 2019-04-25 04:20:54 UTC
RTC time: Thu 2019-04-25 04:20:54
Time zone: UTC (UTC, +0000)
NTP enabled: yes
NTP synchronized: yes
RTC in local TZ: no
DST active: n/a
CentOS Timezone Config Files
- /usr/share/zoneinfo/ – This directory contains the files timezone name wise. For example, the file
/usr/share/zoneinfo/America/New_York
represents time zone for New York. - /etc/localtime – This is a symlink to the file localtime located in
/usr/share/zoneinfo/
directory.
Change Timezone in CentOS
First, you should have long name of timezone which you want to set. You can get the list of all available timezones using below command:
timedatectl list-timezones
It will show output like below:
Africa/Abidjan
Africa/Accra
Africa/Addis_Ababa
Africa/Algiers
Africa/Asmara
Africa/Bamako
Africa/Bangui
...
...
America/Caracas
America/Cayenne
America/Cayman
America/Chicago
America/Chihuahua
America/Costa_Rica
...
...
Pacific/Saipan
Pacific/Tahiti
Pacific/Tarawa
Pacific/Tongatapu
Pacific/Wake
Pacific/Wallis
UTC
Once you get timezone which you want then run the following command as sudo user.
The basic syntax is:
sudo timedatectl set-timezone new_time_zone
For example, if you want to set America/Chicago
timezone then you need to run command as :
sudo timedatectl set-timezone America/Chicago
Now you can verify timezone again using timedatectl
command:
timedatectl
It should show that timezone is changed to America/Chicago
.
Local time: Sat 2019-04-25 12:58:03 CDT
Universal time: Sat 2019-04-25 17:58:03 UTC
RTC time: Sat 2019-04-25 17:58:02
Time zone: America/Chicago (CDT, -0500)
NTP enabled: yes
NTP synchronized: yes
RTC in local TZ: no
DST active: yes
Last DST change: DST began at
Sun 2019-03-10 01:59:59 CST
Sun 2019-03-10 03:00:00 CDT
Next DST change: DST ends (the clock jumps one hour backwards) at
Sun 2019-11-03 01:59:59 CDT
Sun 2019-11-03 01:00:00 CST
Change Timezone By Symlink
You can change timezone by creating a symlink also. This method is useful when your server is running older version of CentOS or not have timedatectl
command is available. We are going to change the timezone by creating symlink /etc/localtime
to the timezone in the /usr/share/zoneinfo
directory.
First, you need to delete current /etc/localtime
symlink or file by typing:
sudo rm -rf /etc/localtime
After that, add the timezone which you want to set and creating a symlink:
sudo ln -s /usr/share/zoneinfo/America/Chicago /etc/localtime
Now, if you want to verify it you can do it by listing the /etc/localtime
file or run the date command:
date
It will show below output:
Output
Thu Apr 25 17:52:58 CDT 2019
Conclusion
Finally, you learned how to change timezone in CentOS 7. You can leave comment if you have any question.
Leave a Reply