Is production: true
#migrated

How to change CentOS timezone

Created: 19 Mar 2023 Modified: 19 Mar 2023 Lang: English



[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

    1
    2
    3
    
    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

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

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

    1
    2
    3
    4
    
    [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

1
2
3
4
5
6
7
8
#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__