Change Timezone on CentOS 7 Server - Do it Now ?

By default, the timezone on CentOS set at the time of installation. CentOS and RedHat still use symbolically linked files to set the system's timezone. Basically, the 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.

Here at LinuxAPT, as part of our Server Management Services, we regularly help our Customers to perform related Linux queries.

In this context, we shall look into how to change timezone on CentOS 7.


How to Get Current Timezone ?

Before proceeding with this procedure, ensure that you are using a user with sudo privileges.

You can get current timezone by simply issuing timedatectl command. Run below command:

$ timedatectl

It will show output as below:

 Local time: Thu 2019-04-25 04:20:54 UTC
  Universal time: Thu 2019-04-25 04:20:54 UTC
        RTC time: Thu 2019-04-25 04:20:54
       Time zone: UTC (UTC, +0000)
     NTP enabled: yes
NTP synchronized: yes
 RTC in local TZ: no
      DST active: n/a


CentOS Timezone Config Files

  • /usr/share/zoneinfo/ – This directory contains the files timezone name wise. For example, the file /usr/share/zoneinfo/America/New_York represents time zone for New York.
  • /etc/localtime – This is a symlink to the file localtime located in /usr/share/zoneinfo/ directory.


How to Change Timezone in CentOS ?

First, you should have long name of timezone which you want to set. You can get the list of all available timezones using below command:

$ timedatectl list-timezones

It will show output like below:

Africa/Abidjan
Africa/Accra
Africa/Addis_Ababa
Africa/Algiers
Africa/Asmara
Africa/Bamako
Africa/Bangui
...
...
America/Caracas
America/Cayenne
America/Cayman
America/Chicago
America/Chihuahua
America/Costa_Rica
...
...
Pacific/Saipan
Pacific/Tahiti
Pacific/Tarawa
Pacific/Tongatapu
Pacific/Wake
Pacific/Wallis
UTC

Once you get timezone which you want then run the following command as sudo user.

The basic syntax is:

$ sudo timedatectl set-timezone new_time_zone

For example, if you want to set America/Chicago timezone then you need to run command as :

$ sudo timedatectl set-timezone America/Chicago

Now you can verify timezone again using timedatectl command:

$ timedatectl

It should show that timezone is changed to America/Chicago.

Local time: Sat 2019-04-25 12:58:03 CDT
  Universal time: Sat 2019-04-25 17:58:03 UTC
        RTC time: Sat 2019-04-25 17:58:02
       Time zone: America/Chicago (CDT, -0500)
     NTP enabled: yes
NTP synchronized: yes
 RTC in local TZ: no
      DST active: yes
 Last DST change: DST began at
                  Sun 2019-03-10 01:59:59 CST
                  Sun 2019-03-10 03:00:00 CDT
 Next DST change: DST ends (the clock jumps one hour backwards) at
                  Sun 2019-11-03 01:59:59 CDT
                  Sun 2019-11-03 01:00:00 CST


How to Change Timezone By Symlink ?

You can change timezone by creating a symlink also. This method is useful when your server is running older version of CentOS or not have

timedatectl command is available. We are going to change the timezone by creating symlink /etc/localtime to the timezone in the /usr/share/zoneinfo directory.

First, you need to delete current /etc/localtime symlink or file by typing:

$ sudo rm -rf /etc/localtime

After that, add the timezone which you want to set and creating a symlink:

$ sudo ln -s /usr/share/zoneinfo/America/Chicago /etc/localtime

Now, if you want to verify it you can do it by listing the /etc/localtime file or run the date command:

$ date

It will show below output:

Output
Thu Apr 25 17:52:58 CDT 2019


[Need help in fixing CentOS Linux System ? We can help you. ]

This article covers how to change timezone in CentOS 7. A time zone is basically a region of the globe that observes a uniform standard time for constitutional, business and cultural purposes.

To get detailed information your CentOS server's date, time, and timezone you use the timedatectl command:

$ timedatectl

To Delete the current /etc/localtime file or symlink:

$ sudo rm -rf /etc/localtime

Related Posts