1月 02, 2020 Ubuntu
每次要裝新機時,都會有機會做一次這個動作。

### 檢查主機時間

可以透過使用以下指令取機主機現時時間:

```sh
$ timedatectl
```

應該會有類似以下的結果 :

```sh
                      Local time: Thu 2020-01-02 04:32:15 UTC
                  Universal time: Thu 2020-01-02 04:32:15 UTC
                        RTC time: Thu 2020-01-02 04:32:15
                       Time zone: Etc/UTC (UTC, +0000)
       System clock synchronized: yes
systemd-timesyncd.service active: yes
                 RTC in local TZ: no
```

預設應該是使用 UTC 的設定。

其實系統的時間是在 `/etc/localtime` 設定的,我們可以查看一下它:

```sh
$ ls -l /etc/localtime
```

會看到它是一個 Symbolic Link 指向一個 zoneinfo 檔案。

```sh
lrwxrwxrwx 1 root root 27 Oct  3 06:18 /etc/localtime -> /usr/share/zoneinfo/Etc/UTC
```

### 使用 timedatectl 來變更 timezone 設定

首先我們可以透過以下指令取得可以使用的 timezone :

```sh
$ timedatectl list-timezones
```

會列出大量的結果:

```sh
Africa/Banjul
Africa/Bissau
Africa/Blantyre
Africa/Brazzaville
Africa/Bujumbura
Africa/Cairo
Africa/Casablanca
Africa/Ceuta
Africa/Conakry
Africa/Dakar
Africa/Dar_es_Salaam
...
```

然後使用 `timedatectl` 變更時區:

```sh
$ sudo timedatectl set-timezone Asia/Hong_Kong
```

上面的指令是變更時區到香港,如要變更其他地方時區則只要填上其他地方便可以。

然後可以再次使用 `timedatectl` 查檢變更後的時區 :

```sh
$ timedatectl
```

現在變更為 Asia/Hong_Kong 了。

```sh
                      Local time: Thu 2020-01-02 12:49:30 HKT
                  Universal time: Thu 2020-01-02 04:49:30 UTC
                        RTC time: Thu 2020-01-02 04:49:30
                       Time zone: Asia/Hong_Kong (HKT, +0800)
       System clock synchronized: yes
systemd-timesyncd.service active: yes
                 RTC in local TZ: no
```
過去文章
2025 (9)
4 (5)
3 (1)
2 (3)
2024 (25)
11 (3)
10 (3)
9 (1)
3 (18)
2022 (6)
10 (1)
6 (2)
5 (1)
3 (1)
1 (1)
2021 (21)
11 (7)
7 (1)
6 (2)
5 (2)
4 (6)
3 (2)
2 (1)
2020 (92)
12 (1)
11 (2)
10 (4)
9 (10)
8 (5)
7 (1)
6 (3)
5 (1)
4 (4)
3 (25)
2 (7)
1 (29)
2019 (57)
12 (25)
11 (7)
9 (25)