Is production: true
#migrated

Title: How to change CentOS timezone

Created: 19 Mar 2023 Modified: 19 Mar 2023

Description:



[Legacy Link]

Based on the [Link] , the local time is configured by link of the file /etc/localtime

[Additional Link from digital ocean(Cofnigure timezone)]

Instructions

  1. Check local timezone

    ls -l /etc/localtime
    #Show output like below message, showing the /etc/localtime is linked with timezone file in zoneinfo
    #/etc/localtime -> ../usr/share/zoneinfo/Asia/Hong_Kong
    
  2. Find out timezone options

    #Find out available timezeon, targeting to hong kong this time
    timedatectl list-timezones | grep Hong_Kong
    #Asia/Hong_Kong
    
  3. Setup timezone

    #Set timezone to the grep result 
    timedatectl set-timezone Asia/Hong_Kong
    
  4. Verify

    [root@host ~]# date
    Fri Oct 11 02:05:11 HKT 2019
    [root@host ~]# ls -l /etc/localtime
    lrwxrwxrwx. 1 root root 36 Oct 11 01:56 /etc/localtime -> ../usr/share/zoneinfo/Asia/Hong_Kong
    

Without timezonectl

The timezone could be changed by directly link target timezone

#Backup the local before update
mv /etc/localtime /etc/localtime__

#Link the timezone under zoneinfo as /etc/localtime
ln -s /usr/share/zoneinfo/Asia/Hong_Kong /etc/localtime

#Remove the /etc/localtime__
rm /etc/localtime__