[ad_1]
Using the correct timezone is essential for many systems related tasks and processes. For example, the cron daemon uses the system’s timezone for executing cron jobs, and the timestamps in the log files are based on the same system’s timezone.
On CentOS, the system’s timezone is set during the install, but it can be easily changed at a later time.
This article describes how to set or change the timezone on CentOS 8 systems.
Checking the Current Timezone #
timedatectl
is a command-line utility that allows you to view and change the system’s time and date. It is available on all modern systemd-based Linux systems:
timedatectl
The output shows the system’s timezone. In this example the timezone is set to UTC:
Local time: Sat 2020-03-21 21:30:22 UTC
Universal time: Sat 2020-03-21 21:30:22 UTC
RTC time: Sat 2020-03-21 21: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 timezone is configured by symlinking /etc/localtime
to a binary timezone identifier in the /usr/share/zoneinfo
directory. Another option to check the timezone is to show the path the symlink points to using the ls
command:
ls -l /etc/localtime
lrwxrwxrwx. 1 root root 23 Nov 21 23:30 /etc/localtime -> /usr/share/zoneinfo/UTC
Changing Timezone in CentOS #
Before changing the timezone, you’ll need to find out the long name for the timezone you want to use. The timezones are using “Region/City” format.
To list all available time zones invoke the timedatectl
command with the list-timezones
option:
timedatectl list-timezones
...
America/Tijuana
America/Toronto
America/Tortola
America/Vancouver
America/Whitehorse
America/Winnipeg
...
Once you identify which time zone is accurate to your location, run the following command as root or user with sudo privileges
:
sudo timedatectl set-timezone your_time_zone
For example, to change the system’s timezone to America/Toronto
:
sudo timedatectl set-timezone America/Toronto
Run the timedatectl
command to verify the changes:
timedatectl
Local time: Sat 2020-03-21 17:43:39 EDT
Universal time: Sat 2020-03-21 21:43:39 UTC
RTC time: Sat 2020-03-21 21:43:40
Time zone: America/Toronto (EDT, -0400)
System clock synchronized: yes
NTP service: active
RTC in local TZ: no
Changing the Timezone by Creating a Symlink #
If you are running an older version of CentOS
and the timedatectl
command is not present on your system, you can change the timezone by symlinking /etc/localtime
to the timezone file in the /usr/share/zoneinfo
directory.
Identify the timezone you want to configure and create a symlink
:
sudo ln -sf /usr/share/zoneinfo/America/Toronto /etc/localtime
Verify the changes either by listing the /etc/localtime
file or issuing the timedatectl
or date
commands:
date
Sat Mar 21 17:46:10 EDT 2020
Conclusion #
We have shown you how to change your CentOS system’s timezone.
If you are facing any problems, feel free to leave a comment.
[ad_2]
Source link