Sep 30, 2023 4 min read

How to Set or Change Timezone on CentOS 7

Set or change the timezone on CentOS 7 with our step-by-step tutorial. An area that has a uniform standard time used to schedule activities.

Set or Change Timezone on CentOS 7
Table of Contents

Choose a different version or distribution

Introduction

Before we begin talking about the steps to set or change Timezone on CentOS 7, let's briefly understand - What is a Timezone?

A timezone is a region of the world that observes a specific standard time offset from Coordinated Universal Time (UTC), used to synchronize clocks and schedule activities.

On Ubuntu, the system’s timezone is set during the installation, and it is easily configurable later. Using the correct timezone is necessary for systems-related tasks and processes like executing the cron jobs, and timestamps in the log files are based on the system's timezone.

In this tutorial, you will set or change the Timezone on CentOS7. We will also address a few FAQs on how to set or change Timezone on CentOS 7.

Prerequisites

1) Make sure to log in as a root user with sudo privileges.

Step 1 - Checking the Current Timezone

1) You can use timedatectl command in CentOS and other modern Linux distros. It will help to display and set the current system’s time and timezone:

timedatectl

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

Output

Local time: Friday 2021-03-09 12:43:42 UTC
  Universal time: Friday 2021-03-09 12:43:42 UTC
        RTC time: Friday 2021-03-09 12:43:42
       Time zone: Etc/UTC (UTC, +0000)
     NTP enabled: no
NTP synchronized: yes
 RTC in local TZ: no
      DST active: n/a

2) The configuration of the system timezone is by done symlinking /etc/localtime to a binary timezone identifier in /usr/share/zoneinfo directory. You can also check the timezone by showing the path symlink points to using the ls command:

ls -l /etc/localtime
Output

lrwxrwxrwx. 1 root root 03 September 11 09:25 /etc/localtime -> ../usr/share/zoneinfo/Etc/UTC

Step 2 - Changing Timezone in the CentOS

1) You need to find the long name for the timezone before changing the timezone. "Region/City" format is followed as a naming convention for the timezone.

2) Either list the files in /usr/share/zoneinfo directory or use the timedatectl command to list all the available timezones:

timedatectl list-timezones
Output

...
America/Tijuana
America/Toronto
America/Tortola
America/Vancouver
America/Whitehorse
America/Winnipeg
...

3) After, identifying the time zone is accurate to your location then, run the below command as sudo user:

sudo timedatectl set-timezone your_time_zone

4) If you want to change the system’s timezone to the America/Toronto, using the following command:

sudo timedatectl set-timezone America/Toronto

5) After that, run the timedatectl command to verify the changes:

timedatectl
Output

Local time: Fri 2021-09-03 13:47:10 EST
  Universal time: Fri 2021-09-03 12:47:10 UTC
        RTC time: Fri 2021-09-03 12:47:10
       Time zone: America/Toronto (EST, -0500)
     NTP enabled: no
NTP synchronized: yes
 RTC in local TZ: no
      DST active: no
 Last DST change: DST ended at
                  Sun 2020-11-04 01:59:59 EDT
                  Sun 2020-11-04 01:00:00 EST
 Next DST change: DST begins (the clock jumps one hour forward) at
                  Sun 2020-03-10 01:59:59 EST
                  Sun 2020-03-10 03:00:00 EDT

1) timedatectl command will be there on your system if you are running an older command. You will have to change the timezone by symlinking /etc/localtime to the timezone file in the /usr/share/zoneinfo directory.

2) Next, delete the current /etc/localtime file or symlink, by:

sudo rm -rf /etc/localtime

3) You will then need to identify the timezone you want to configure and create a symlink:

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

4) You will now verify it either by listing /etc/localtime file or by issuing the date command:

date
Output

Fri Sept  3 12:52:58 EST 2021

FAQ's on how to set or change Timezone on CentOS 7

Can I list all available timezones on CentOS 7?

Yes, you can use the timedatectl command with the list-timezones option to view a complete list of available timezones: timedatectl list-timezones.

What is the command to set the timezone on CentOS 7? 

To set the timezone, use the timedatectl command with the set-timezone option followed by the desired timezone: sudo timedatectl set-timezone <timezone>.

Do I need root privileges to change the timezone? 

Yes, changing the system timezone on CentOS 7 requires root privileges. Prepend the timedatectl command with sudo to execute it as the superuser.

How do I determine the correct timezone for my location? 

You can find the appropriate timezone for your location by searching for its name or geographical region in the list of available timezones provided by CentOS 7.

Can I set the timezone to a specific city or region? 

Yes, CentOS 7 allows you to set the timezone to a specific city or region. Use the continent/city format when specifying the timezone.

After changing the timezone, do I need to restart the system? 

CentOS 7 dynamically adapts to the updated timezone without requiring a system restart. The new setting takes effect immediately.

Can I verify the timezone change after updating it? 

Yes, you can verify the changed timezone by executing the timedatectl command again: timedatectl show --property=Timezone.

Conclusion

Setting or changing the timezone on CentOS 7 is a straightforward process that ensures accurate time representation and synchronization with other systems.

We hope this detailed guide helped you to set or change Timezone on the CentOS 7.

If you have any queries, please leave a comment below and, we’ll be happy to respond to them for sure.

Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to DevOps Tutorials - VegaStack.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.