温馨提示×

时间戳错误Ubuntu怎么解决

小樊
78
2026-08-23 21:22:37
栏目: 智能运维

“时间戳错误”在 Ubuntu 里可能指好几种情况,不同原因解决方法不一样。下面我按最常见场景给你排查和解决,你可以对照使用。


一、系统时间不对(最常见)

1️⃣ 查看当前时间

timedatectl

重点看:

  • Local time
  • RTC time
  • System clock synchronized

2️⃣ 时区错误(最常见)

查看当前时区

timedatectl

设置时区(例如中国)

sudo timedatectl set-timezone Asia/Shanghai

3️⃣ 时间同步失败(NTP 问题)

开启自动时间同步

sudo timedatectl set-ntp true

如果还是不同步

安装并启用 NTP 服务:

sudo apt update
sudo apt install systemd-timesyncd
sudo systemctl enable systemd-timesyncd
sudo systemctl start systemd-timesyncd

二、BIOS / 硬件时间错误(双系统常见)

现象

  • Ubuntu 时间慢 8 小时
  • Windows 时间正常

原因

Ubuntu 默认认为 硬件时间是 UTC Windows 认为是 本地时间

✅ 解决方法(推荐)

让 Ubuntu 使用本地时间:

timedatectl set-local-rtc 1

✅ 适合 Windows + Ubuntu 双系统

⚠️ 不推荐反过来改 Windows(容易出问题)


三、文件时间戳错误(编译 / make 报错)

常见报错

  • Clock skew detected
  • modification time in the future

原因

系统时间比文件时间还“早”

解决方法

方法 1:同步时间(推荐)

sudo ntpdate -s time.nist.gov

方法 2:重新设置文件时间

touch 文件名

或批量修复:

find . -type f -exec touch {} \;

四、虚拟机时间漂移(VMware / VirtualBox)

临时修复

sudo hwclock --hctosys

永久解决

sudo apt install open-vm-tools
sudo systemctl enable open-vm-tools

VirtualBox:

sudo apt install virtualbox-guest-utils

五、日志 / 证书 / HTTPS 时间戳错误

现象

  • HTTPS 证书无效
  • Certificate has expired

原因

系统时间年份错误

解决

✅ 先修正系统时间(见第一部分)

然后:

sudo apt update
sudo apt install --reinstall ca-certificates

六、快速一键修复(最常用)

sudo timedatectl set-timezone Asia/Shanghai
sudo timedatectl set-ntp true
sudo hwclock --hctosys

七、如果你愿意,我可以更精确帮你

你可以直接把下面信息发我:

  1. 报错原文(复制粘贴)
  2. 是 系统时间 / 文件时间 / 编译错误 / 浏览器证书错误
  3. 是否 双系统 / 虚拟机

我可以一步一步带你修 ✅

0 踩