在新版的ubuntu中,使用timedatectl 替換了ntpdate來進行時間管理。
1.查看當前時間狀態
查看當前時間狀態 timedatectl status :
1 res@ubuntu:~$ timedatectl status 2 Local time: 三 2019-01-02 17:22:13 PST 3 Universal time: 四 2019-01-03 01:22:13 UTC 4 RTC time: 三 2019-01-02 17:22:14 5 Time zone: America/Los_Angeles (PST, -0800) 6 System clock synchronized: yes 7 systemd-timesyncd.service active: yes 8 RTC in local TZ: yes
系統顯示的時間是錯誤的,錯誤原因也是顯而易見的,使用的是America/Los_Angeles的時區。
因此只要修改時區就能保證時間的正確。
2.修改時區
所有的時區名稱存儲在/usr/share/zoneinfo文件中。
執行命令timedatectl set-timezone "Asia/Shanghai" 就可以將時區設為上海時區。
1 res@ubuntu:~$ timedatectl set-timezone "Asia/Shanghai"
重新查看當前時間狀態 timedatectl status :
1 res@ubuntu:~$ timedatectl status 2 Local time: 四 2019-01-03 10:59:05 CST 3 Universal time: 四 2019-01-03 02:59:05 UTC 4 RTC time: 四 2019-01-03 10:59:05 5 Time zone: Asia/Shanghai (CST, +0800) 6 System clock synchronized: no 7 systemd-timesyncd.service active: yes 8 RTC in local TZ: yes
此時時間已經正常了。