Using the correct time zone is essential for many system-related tasks and processes. For example: the cron daemon uses the system time zone to execute cron tasks, and the timestamp in the log file is also based on the system time zone.
On CentOS, the system time zone is set during the installation process, and it can be easily modified later.
This article describes how to set or modify the time zone on CentOS 8 system.
timedatectl
is a command line tool that allows you to view and modify the system time and date. It can be used in all modern systemd-based Linux systems:
timedatectl
The output shows the time zone of the system. In this example, the time zone is set to UTC:
Local time: Sat 2020-03-2121:30:22 UTC
Universal time: Sat 2020-03-2121:30:22 UTC
RTC time: Sat 2020-03-2121:30:22
Time zone:UTC(UTC,+0000)
System clock synchronized: yes
NTP service: active
RTC in local TZ: no
If you get a warning saying, "The system is configured to read the RTC time in the local time zone.", run the following command to use RTC in UTC:
timedatectl
The system time zone is configured through the link file /etc/localtime
, which points to a binary time zone identification file in the /usr/share/zoneinfo
directory. Another way to check the time zone is to display the actual path the linked file points to, using the ls
command:
ls -l /etc/localtime
lrwxrwxrwx.1 root root 23 Nov 2123:30/etc/localtime ->/usr/share/zoneinfo/UTC
When changing the time zone, you will need to find a long name for the time zone you want to use. The time zone usually uses the "region/city" format.
To list all available time zones, run the timedatectl
command and add the list-timezones
option:
timedatectl list-timezones
...
America/Tijuana
America/Toronto
America/Tortola
America/Vancouver
America/Whitehorse
America/Winnipeg
...
Once you have identified which time zone is ready to describe your location, as root or another user with sudo privileges, run the following command:
sudo timedatectl set-timezone your_time_zone
For example, to set the system time zone to America/Toronto
:
sudo timedatectl set-timezone America/Toronto
Run the timedatectl
command to verify the modification:
timedatectl
Local time: Sat 2020-03-2117:43:39 EDT
Universal time: Sat 2020-03-2121:43:39 UTC
RTC time: Sat 2020-03-2121:43:40
Time zone: America/Toronto(EDT,-0400)
System clock synchronized: yes
NTP service: active
RTC in local TZ: no
If you are running an older CentOS version, and timedatectl
is not available on your system, you can modify the time zone link file /etc/localtime
to the time zone under the directory /usr/share/zoneinfo
File to modify the time zone.
Identify the time zone you want to configure, and create a link file:
sudo ln -sf /usr/share/zoneinfo/America/Toronto /etc/localtime
Verify the modification by listing the /etc/localtime
file or triggering the timedatectl
or date
command:
date
Sat Mar 2117:46:10 EDT 2020
We have shown how to modify the time zone of your CentOS system.
Recommended Posts