Ubuntu 同步北京时间教程
- 设置时区为北京时间
sudo timedatectl set-timezone Asia/Shanghai
- 开启自动同步时间
sudo timedatectl set-ntp true
- 重启时间同步服务
sudo systemctl restart systemd-timesyncd
- 检查同步状态
timedatectl
- 用 24 小时制查看当前时间
date "+%Y-%m-%d %H:%M:%S %Z"
判断是否成功,重点看这几项:
Time zone: Asia/Shanghai (CST, +0800)
System clock synchronized: yes
NTP service: active
一键执行:
sudo timedatectl set-timezone Asia/Shanghai
sudo timedatectl set-ntp true
sudo systemctl restart systemd-timesyncd
timedatectl
date "+%Y-%m-%d %H:%M:%S %Z"
- 强制手动修改服务器时间
先关闭自动同步:
sudo timedatectl set-ntp false
再强制设置时间:
sudo timedatectl set-time "2026-03-26 12:34:56"
|