Website-Icon DED9

How to Change Time Zone in CentOS?

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 7.

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 7, 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 the time zone in CentOS 7.

First of all, we need to access your VPS server using SSH.

date

This command outputs the time in the following format:

Fri Mar 15 14:52:20 UTC 2019

 

You can also use the timedatectl command. This command can do the following for you:

The main command is as follows:
timedatectl
The output is as shown below:

Local time: Fri 20190315 14:54:51 UTC
Universal time: Fri 20190315 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 7

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 set Timezone in CentOS – CentOS tradition

Once you have the list of time zones, you can set the time zone you want. You can use the following to set the time zone in CentOS 7

timedatectl set-timezone America/Chicago

You can replace the time zone in the above command accordingly. Here we can also set a specific time and date. This can be done using the following format:

timedatectl set-time 'YYYY-MM-DD HH:MM:SS'

For example, if you want this time to be set as Mar-16-2019 and the current time as 09:20:00, you can use the following code:
timedatectl set-time '2019-03-16 09:20:00'
After making these changes, you can again check the time zone details using timedatectl.

How to set hardware clock in CentOS 7

The hardware clock is different from the system clock which is managed by the Linux kernel. This clock is also called BIOS. The hardware clock is activated when the system is turned off. You can set the hardware clock using Linux commands.

To verify that the hardware clock is set to the local time zone, use the following command:

timedatectl | grep local
This outputs as shown below, which means that the hardware clock does not have a specific time zone:

RTC in local TZ: no

 

Next, you can set your hardware clock to the local time zone using the following command:
timedatectl set-local-rtc 1
To revert the changes, you can use the following:
timedatectl set-local-rtc 0

How to do clock synchronization on CentOS 7

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

Die mobile Version verlassen