In this tutorial, you will learn how to check and set your Timezone in CentOS.
timedatectl command is a relatively new addition to Systemd distributions, and provides a much simpler interface for viewing and adjusting a server’s date and time.
CentOS and RedHat still use symbolically linked files to set the system’s timezone. You will also learn how to view this linked file and how to update your timezone by changing the link.
Check Current Timezone with Timedatectl
To get detailed information your CentOS server’s date, time, and timezone you use the
timedatectl command. In the example below, we can see the server’s time zone is America/New_York, and the offset is -0400.
Local time: Fri 2020-09-04 23:44:41 EDT Universal time: Sat 2020-09-05 03:44:41 UTC RTC time: Sat 2020-09-05 03:44:39 Time zone: America/New_York (EDT, -0400) System clock synchronized: no NTP service: active RTC in local TZ: no
Setting Timezone with Timedatectl
In order to set your timezone you should probably list the available zones. You can view a list of supported timezones using the
timedatectl list-timezones command.
Africa/Abidjan Africa/Accra Africa/Addis_Ababa Africa/Algiers Africa/Asmara Africa/Bamako Africa/Bangui Africa/Banjul Africa/Bissau Africa/Blantyre Africa/Brazzaville Africa/Bujumbura Africa/Cairo Africa/Casablanca Africa/Ceuta Africa/Conakry Africa/Dakar Africa/Dar_es_Salaam Africa/Djibouti Africa/Douala ...
The list is fairly comprehensive. You could browse the list by piping the
timedatectl command into the
If you have an idea which timezone you want, you can pipe
timedatectl into the
timedatectl list-timezones | grep America
... America/Noronha America/North_Dakota/Beulah America/North_Dakota/Center America/North_Dakota/New_Salem America/Nuuk America/Ojinaga America/Panama America/Pangnirtung America/Paramaribo America/Phoenix America/Port-au-Prince America/Port_of_Spain America/Porto_Velho America/Puerto_Rico America/Punta_Arenas America/Rainy_River America/Rankin_Inlet America/Recife ...
Once you have the timezone you want to set the system to, you use the
timedatectl set-timezone command with the name of the timezone. For example, to set the server’s timezone to America/Phoenix, you would run the following command.
sudo timedatectl set-timezone America/Phoenix
Setting Timezone with Symbolic Link
The timezone on a RedHat and CentOS server is stored set by the
/etc/localtime file. This file is actually a symbolic link to a timezone file under
To get a basic view of the timezone you can
ls the file to it’s symbolic link.
ls -la /etc/localtime
lrwxr-xr-x 1 root wheel 41 30 Aug 22:12 /etc/localtime -> /var/db/timezone/zoneinfo/America/Toronto
In the example above, we can see the
/etc/localtime file is symbolically linked to the
America/Toronto timezone file.
To change the timezone, replace the symbolic link with that of the correct timezone file for your server.
sudo ln -sf /usr/share/zoneinfo/America/Phoenix
ln command is used to create file links, while the
-s flag is used to set the link type as symbolic and the
-f flag forces the creation, which is required to update an existing link.