時間

時區設定

依選項選擇你在的時區

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

參考資料