How To Set or Change Timezone on CentOS 7.

How To Set Or Change Timezone On CentOS 7.

This tutorial explains how to set or change the timezone on CentOS 7.

To be able change the system’s timezone you’ll need to be logged in as root or user with sudo privileges .

 

Checking the Current Timezone

In CentOS and other modern Linux distros, you can use the timedatectl command to display and set the current system’s time and timezone.

timedatectl

The output below shows that the system’s timezone is set to UTC:

 Local time: Wed 2023-06-21 05:09:09 EDT
  Universal time: Wed 2023-06-21 09:09:09 UTC
        RTC time: Wed 2023-06-21 09:09:09
       Time zone: America/New_York (EDT, -0400)
     NTP enabled: yes
NTP synchronized: yes
 RTC in local TZ: no
      DST active: yes
 Last DST change: DST began at
                  Sun 2023-03-12 01:59:59 EST
                  Sun 2023-03-12 03:00:00 EDT
 Next DST change: DST ends (the clock jumps one hour backwards) at
                  Sun 2023-11-05 01:59:59 EDT
                  Sun 2023-11-05 01:00:00 EST

The system timezone is configured by symlinking /etc/localtime to a binary timezone identifier in the /usr/share/zoneinfo directory. So, 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 38 Sep 25  2021 /etc/localtime -> ../usr/share/zoneinfo/America/New_York

 

Changing Timezone in CentOS

To list all available time zones, you can either list the files in the /usr/share/zoneinfo directory or use the timedatectl command.

timedatectl list-timezones
...
Europe/Athens
Europe/Belgrade
Europe/Berlin
Europe/Bratislava
Europe/Brussels
Europe/Bucharest
Europe/Budapest
Europe/Busingen
Europe/Chisinau
Europe/Copenhagen
Europe/Dublin
...

Once you identify which time zone is accurate to your location, run the following command as sudo user:

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: Wed 2023-06-21 12:12:47 EEST
  Universal time: Wed 2023-06-21 09:12:47 UTC
        RTC time: Wed 2023-06-21 09:12:46
       Time zone: Europe/Bucharest (EEST, +0300)
     NTP enabled: yes
NTP synchronized: yes
 RTC in local TZ: no
      DST active: yes
 Last DST change: DST began at
                  Sun 2023-03-26 02:59:59 EET
                  Sun 2023-03-26 04:00:00 EEST
 Next DST change: DST ends (the clock jumps one hour backwards) at
                  Sun 2023-10-29 03:59:59 EEST
                  Sun 2023-10-29 03:00:00 EET

 

Delete the current /etc/localtime file or symlink:

sudo rm -rf /etc/localtime

Identify the timezone you want to configure and create a symlink :

sudo ln -s /usr/share/zoneinfo/America/Toronto /etc/localtime

You can verify it either by listing the /etc/localtime file or issuing the date command:

date
Wed Jun 21 12:14:47 EEST 2023

 

Conclusion

In this guide, we have shown you how change your CentOS system’s timezone.