【Linux】设置时区

Posted by 西维蜀黍 on 2022-03-24, Last Modified on 2023-08-23

View Timezone

$ timedatectl
                      Local time: Wed 2019-01-23 22:45:47 UTC
                  Universal time: Wed 2019-01-23 22:45:47 UTC
                        RTC time: Wed 2019-01-23 22:45:48
                       Time zone: Etc/UTC (UTC, +0000)
       System clock synchronized: yes
systemd-timesyncd.service active: yes
                 RTC in local TZ: no

The system timezone is configured by symlinking /etc/localtime to a binary timezone identifier in the /usr/share/zoneinfo directory.

ls -l /etc/localtimeCopy
lrwxrwxrwx 1 root root 27 Dec 10 12:59 /etc/localtime -> /usr/share/zoneinfo/Etc/UTC

Alternatively, you can also check the current system’s timezone by displaying the contents of the /etc/timezone file.

$ cat /etc/timezoneCopy
Etc/UTC

Changing the Timezone Using the timedatectl

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-timezonesCopy
...
Europe/Oslo
Europe/Paris
Europe/Podgorica
Europe/Prague
Europe/Riga
Europe/Rome
Europe/Samara
...

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

Reference