How to change time zone in CentOS?
While setting up a new server, you may often have to set the time zone. In certain cases, you may want to change your time zone.
Setting the correct time zone on servers is something that many of us forget. Setting the wrong time zone will affect your server log and logs. That’s why in this tutorial, we will show you how to set a time zone in CentOS 8.
Setting the correct time zone for your CentOS-based VPS is important to accurately log time events, otherwise you may end up with a wrong date and time event being logged in the error log.
Apart from logging and reporting, another very important factor is the time set for cron jobs and automated items. By setting an inappropriate time zone, the trends may be considered at a different time than the real time. Fortunately, if you want to set the time zone on CentOS 8, you only need to use a few simple commands!
In general, not setting the correct time zone won’t kill your performance, but it will definitely improve your workflow and easily avoid unclear reports.
So let’s learn how to set time zone in CentOS 8.
How to check the zone set in CentOS 8
First of all, we need to access your VPS server using SSH. If you have problems, refer to the tutorial on how to use PuTTY – SSH Terminal!
You can check your current time zone as shown below:
date
This command outputs the time in the following format:
Fri Mar 15 14:52:20 UTC 2024
You can also use the timedatectl command. This command can do the following for you:
Review dates and times
Change the date and time
Set a time zone for the system
Enable automatic clock synchronization based on a remote server
The main command is as follows:
timedatectl
Local time: Fri 2019-03-15 14:54:51 UTC
Universal time: Fri 2019-03-15 14:54:51 UTC
RTC time: n/a
Time zone: Host (UTC, +0000)
NTP enabled: n/a
NTP synchronized: yes
RTC in local TZ: no
DST active: n/a
It contains information such as local time, world time and time zone.
How to list timezones in CentOS 8
Once you see your current time zone, you may want to list all available time zone options. The following command can be used to list all time zone options:
timedatectl list-timezones
You will get a long list showing all the time zones in alphabetical order.
You can refine your search by adding filters using grep patterns.
One of these examples is as follows:
timedatectl list-timezones | grep Pacific
How to synchronize the clock in CentOS 8
Network Time Protocol (NTP) is an Internet protocol commonly used to synchronize system clocks on different computers. The timedatectl command can configure the system time zone to automatically synchronize with a remote server using NTP.
To enable this, we must first install NTP on the system. To start synchronizing with a remote NTP server, use the following command:
timedatectl set-ntp true
If you want to revert these changes, use the following command. This disables time synchronization:
timedatectl set-ntp false