YouTube Icon

Code Playground.

How To Set or Change Timezone on CentOS 7

CFG

How To Set or Change Timezone on CentOS 7

On CentOS, the framework's timezone is set during the introduce, however it tends to be handily changed sometime in the not too distant future. 

Utilizing the right timezone is significant for some, frameworks related undertakings and cycles. For instance, the cron daemon utilizes the framework's timezone for executing cron occupations, and the timestamps in the log records depend on a similar framework's timezone. 

This instructional exercise discloses how to set or change the timezone on CentOS 7. 

Prerequisites

To be capable change the framework's timezone you'll should be signed in as root or client with sudo advantages . 

Checking the Current Timezone

In CentOS and other present day Linux distros, you can utilize the timedatectl order to show and set the current framework's time and timezone. 

timedatectl

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

      Local time: Wed 2019-02-06 22:43:42 UTC
  Universal time: Wed 2019-02-06 22:43:42 UTC
        RTC time: Wed 2019-02-06 22:43:42
       Time zone: Etc/UTC (UTC, +0000)
     NTP enabled: no
NTP synchronized: yes
 RTC in local TZ: no
      DST active: n/a

The framework timezone is arranged by symlinking/and so forth/localtime to a paired timezone identifier in the/usr/share/zoneinfo index. In this way, another choice to check the timezone is to show the way the symlink focuses to utilizing the ls order : 

ls -l /etc/localtime
lrwxrwxrwx. 1 root root 29 Dec 11 09:25 /etc/localtime -> ../usr/share/zoneinfo/Etc/UTC

Changing Timezone in CentOS

Prior to changing the timezone, you'll have to discover the long name for the timezone you need to utilize. The timezone naming show typically utilizes a "District/City" design. 

To list all accessible time regions, you can either list the documents in the/usr/share/zoneinfo registry or utilize the timedatectl order. 

timedatectl list-timezones
...
America/Tijuana
America/Toronto
America/Tortola
America/Vancouver
America/Whitehorse
America/Winnipeg
...

When you distinguish which time region is exact to your area, run the accompanying order as sudo client: 

sudo timedatectl set-timezone your_time_zone

For instance, to change the framework's timezone to America/Toronto: 

sudo timedatectl set-timezone America/Toronto

Run the timedatectl order to check the changes: 

timedatectl
      Local time: Wed 2019-02-06 17:47:10 EST
  Universal time: Wed 2019-02-06 22:47:10 UTC
        RTC time: Wed 2019-02-06 22: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 2018-11-04 01:59:59 EDT
                  Sun 2018-11-04 01:00:00 EST
 Next DST change: DST begins (the clock jumps one hour forward) at
                  Sun 2019-03-10 01:59:59 EST
                  Sun 2019-03-10 03:00:00 EDT

Changing the Timezone by Creating a Symlink

On the off chance that you are running a more seasoned form of CentOS and the timedatectl order is absent on your framework, you can change the timezone by symlinking/and so forth/localtime to the timezone record in the/usr/share/zoneinfo index. 

Erase the current/and so on/localtime document or symlink: 

sudo rm -rf /etc/localtime

Distinguish the timezone you need to arrange and make a symlink : 

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

You can check it either by posting the/and so on/localtime record or giving the date order: 

date
Wed Feb  6 17:52:58 EST 2019

Conclusion

In this guide, we have demonstrated you how change your CentOS framework's timezone. 

Don't hesitate to leave a remark on the off chance that you have any inquiries.




CFG