时间

时区设定

依选项选择你在的时区

sudo tzselect

更换时区档

sudo cp /usr/share/zoneinfo/Asia/Taipei /etc/localtime

对时

sudo apt-get install ntpdate
sudo ntpdate time.stdtime.gov.tw

时间写入 BIOS

sudo hwclock -w

每日对时

sudo crontab -e

cronjob

0 0 * * *  /usr/sbin/ntpdate time.stdtime.gov.tw > /dev/null

若 ntpdate 路径与我不太一样,可以使用 which ntpdate 去查看看您的真实路径为何

列出所有可用时区

$ timedatectl list-timezones
$ timedatectl list-timezones
Africa/Accra
Africa/Addis_Ababa
Africa/Algiers
Africa/Asmara
Africa/Bamako
Africa/Bangui
Africa/Banjul
Africa/Bissau
Africa/Blantyre
Africa/Brazzaville
Africa/Bujumbura
Africa/Cairo
Africa/Casablanca
Africa/Ceuta
Africa/Conakry
Africa/Dakar
Africa/Dar_es_Salaam
Africa/Djibouti
Africa/Douala
Africa/El_Aaiun
Africa/Freetown
Africa/Gaborone
Africa/Harare
Africa/Johannesburg
Africa/Juba
Africa/Kampala
Africa/Khartoum
Africa/Kigali
Africa/Kinshasa
Africa/Lagos
Africa/Libreville
Africa/Lome
Africa/Luanda
Africa/Lubumbashi
Africa/Lusaka
Africa/Malabo
Africa/Maputo
Africa/Maseru
Africa/Mbabane
Africa/Mogadishu
Africa/Monrovia
Africa/Nairobi
Africa/Ndjamena
Africa/Niamey
Africa/Nouakchott
Africa/Ouagadougou
Africa/Porto-Novo
Africa/Sao_Tome
Africa/Tripoli
Africa/Tunis
Africa/Windhoek
America/Adak

列出所有亚洲可用时区

$ timedatectl list-timezones | grep Asia
$ timedatectl list-timezones | grep Asia
Asia/Aden
Asia/Almaty
Asia/Amman
Asia/Anadyr
Asia/Aqtau
Asia/Aqtobe
Asia/Ashgabat
Asia/Atyrau
Asia/Baghdad
Asia/Bahrain
Asia/Baku
Asia/Bangkok
Asia/Barnaul
Asia/Beirut
Asia/Bishkek
Asia/Brunei
Asia/Chita
Asia/Choibalsan
Asia/Colombo
Asia/Damascus
Asia/Dhaka
Asia/Dili
Asia/Dubai
Asia/Dushanbe
Asia/Famagusta
Asia/Gaza
Asia/Hebron
Asia/Ho_Chi_Minh
Asia/Hong_Kong
Asia/Hovd
Asia/Irkutsk
Asia/Jakarta
Asia/Jayapura

timedatectl 检查时区设定

$ timedatectl
$ timedatectl
                      Local time: Tue 2021-08-31 11:13:12 CST
                  Universal time: Tue 2021-08-31 03:13:12 UTC
                        RTC time: Tue 2021-08-31 03:13:13
                       Time zone: Etc/UTC (CST, +0800)
       System clock synchronized: yes
systemd-timesyncd.service active: yes
                 RTC in local TZ: no

设定时区

$ timedatectl set-timezone <你要设定的时区>
$ timedatectl set-timezone Asia/Taipei
$ timedatectl
                      Local time: Tue 2021-08-31 11:25:01 CST
                  Universal time: Tue 2021-08-31 03:25:01 UTC
                        RTC time: Tue 2021-08-31 03:25:02
                       Time zone: Asia/Taipei (CST, +0800)
       System clock synchronized: yes
systemd-timesyncd.service active: yes
                 RTC in local TZ: no
$ timedatectl set-timezone Asia/Bangkok
$ timedatectl
                      Local time: Tue 2021-08-31 10:26:47 +07
                  Universal time: Tue 2021-08-31 03:26:47 UTC
                        RTC time: Tue 2021-08-31 03:26:47
                       Time zone: Asia/Bangkok (+07, +0700)
       System clock synchronized: yes
systemd-timesyncd.service active: yes
                 RTC in local TZ: no

/usr/share/zoneinfo/iso3166.tab: No such file or directory

$ sudo tzselect
/usr/bin/tzselect: line 180: /usr/share/zoneinfo/iso3166.tab: No such file or directory
/usr/bin/tzselect: time zone files are not set up correctly

若在设定时区时出现 /usr/share/zoneinfo/iso3166.tab: No such file or directory 问题,可以重新安装时区套件即可解决

sudo apt-get install tzdata

参考资料