本文发布于814 天前,其中的信息可能已经过时,如有错误请发送邮件到919293678#qq.com
在新版的ubuntu中,使用timedatectl 替换了ntpdate来进行时间管理。
查看当前时间状态
timedatectl status
输出结果如下
Local time: Wed 2018-11-21 01:23:33 UTC Universal time: Wed 2018-11-21 01:23:33 UTC RTC time: Wed 2018-11-21 01:23:33 Time zone: Etc/UTC (UTC, +0000) System clock synchronized: yes systemd-timesyncd.service active: yes RTC in local TZ: no
系统显示的时间是错误的,错误原因也是显而易见的,使用的是Etc/UTC的时区。
因此只要修改时区就能保证时间的正确。
修改时区
所有的时区名称存储在/usr/share/zoneinfo文件中。
执行以下命令,将系统设为上海时区
timedatectl set-timezone "Asia/Shanghai"
重新查看当前时间状态
timedatectl status
输出结果如下
Local time: Wed 2018-11-21 09:24:48 CST Universal time: Wed 2018-11-21 01:24:48 UTC RTC time: Wed 2018-11-21 01:24:48 Time zone: Asia/Shanghai (CST, +0800) System clock synchronized: yes systemd-timesyncd.service active: yes RTC in local TZ: no
此时,时间已经正常了。