在 Ubuntu 系统中,“时间戳校对”通常包含两个方面:
date +%s 输出的 Unix 时间戳)是否准确下面按常见场景说明。
date
查看系统时间。
date +%s
查看当前 Unix 时间戳(自 1970-01-01 UTC 起的秒数)。
timedatectl
查看时间、时区、NTP 状态等。
Ubuntu 通常自带 systemd-timesyncd。
查看状态:
timedatectl status
启用并启动:
sudo timedatectl set-ntp true
检查同步状态:
systemctl status systemd-timesyncd
安装:
sudo apt update
sudo apt install chrony
启动:
sudo systemctl enable --now chrony
查看同步情况:
chronyc tracking
sudo apt install ntpdate
sudo ntpdate pool.ntp.org
⚠️ 注意:ntpdate 已逐渐不推荐使用,建议用 NTP 服务长期同步。
sudo date -s "2026-01-21 15:30:00"
设置时区:
sudo timedatectl set-timezone Asia/Shanghai
date -u +%s
UTC 时间戳。
如果你怀疑“时间戳不对”,常见原因:
如果是 VMware / KVM / VirtualBox:
sudo timedatectl set-ntp true
并确保宿主机时间正确。
如果你能说明:
lsb_release -a)我可以给你更精确的校对方案。