大家好,我是冯哥的缓存。装过Linux/windows双系统的朋友,几乎都遇到过一个让人心塞的问题:在 Linux 里把时间调对了,切回 Windows 时间就乱了;在 Windows 里调对了,切回 Linux 又乱了。 两个系统互相"改时间",没完没了。
这篇来就来聊一下这个问题——它不是Bug,是两个系统对"时钟"的理解不同导致的。
一、先搞清楚:电脑里有几个时钟?
很多人不知道,电脑里其实有两套时钟:
开机的时候,操作系统会从 RTC 读一个初始值,然后用软件时钟接管计时。关机的时候,操作系统会把时间写回 RTC,这样下次开机还能读到正确时间。
问题就出在这个"写回 RTC"的动作上。
二、问题的根本原因:UTC 还是本地时间
RTC 里存的是什么格式的时间?
这是争论的核心。RTC 只是一个计时器,它存的是一串数字,但这个数字代表"世界协调时(UTC)"还是"当地时间",是操作系统说了算的。
| | |
|---|
| Windows | 本地时间(Local Time) | |
| Linux | UTC 时间 | RTC 存的是 UTC+0,系统显示时再加时区偏移 |
举个例子:
北京时间是 2026 年 6 月 17 日 上午 09:00(UTC+8)
两种格式,RTC 里存的值相差了整整 8 小时。
三、双系统时间打架的具体过程
来模拟一下这个“扯被子”的过程:
初始状态:RTC = 09:00(本地时间,Windows 存进去的)
→ 开机进 Linux
Linux 读 RTC = 09:00,当作 UTC 解读
Linux 显示时间 = 09:00 + 8h = 17:00(多了8小时!)
用户很困惑,手动把 Linux 时间改成 09:00
Linux 关机,把 UTC 09:00 写回 RTC = 09:00(没变化?)
……但 Linux 理解的 UTC 09:00 对应本地时间 17:00
→ 开机进 Windows
Windows 读 RTC = 09:00,当作本地时间
Windows 显示 09:00(正确!Linux 没改坏)
→ 再开机进 Linux
Linux 读 RTC = 09:00,当作 UTC = 显示 17:00(又错了!)
Windows存本地时间→Linux读成UTC→Linux显示快了8小时→用户手动改→关机时Linux又写回RTC→Windows读出来又不对
实际情况更乱,因为两个系统都可能在关机时往 RTC 写时间,互相覆盖。
两个系统读同一个 RTC,但用不同的解释方式。
四、解决方法:让两个系统统一口径
解决方法只有一个思路:让两个系统用同一种格式解读 RTC。
有两条路:
方案A:让 Linux 改用本地时间(推荐)
这是对双系统用户最省事的方案——Windows 不用动,只改 Linux。
# 告诉 Linux:RTC 里存的是本地时间
sudo timedatectl set-local-rtc 1 --adjust-system-clock
# 验证
timedatectl
timedatectl 输出示例:
Local time: Wed 2026-06-17 09:00:00 CST
Universal time: Wed 2026-06-17 01:00:00 UTC
RTC time: Wed 2026-06-17 09:00:00 ← RTC 存本地时间
Time zone: Asia/Shanghai (CST, +0800)
System clock synchronized: yes
NTP service: active
RTC in local TZ: yes ← 已切换成本地时间
看到 RTC in local TZ: yes 就说明设置成功了。
⚠️ 注意: 执行这条命令后,如果系统时间显示不对,假设当前时间为2026年6月17日9:00点,用 sudo timedatectl set-time "2026-06-17 09:00:00" 或者 sudo date -s "2026-06-17 09:00:00" 手动校正,之后会自动走 NTP 同步。
方案B:让 Windows 改用 UTC(不推荐普通用户)
这个方案反过来——改 Windows,让它也用 UTC 存 RTC。
以管理员身份打开 CMD,运行:
cmd
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation" /v RealTimeIsUniversal /t REG_DWORD /d 1 /f
或者用 PowerShell:
powershell
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\TimeZoneInformation" -Name "RealTimeIsUniversal" -Value 1 -Type DWord
如果因为某些原因必须改Windows,改完后可能需要重启两次才能生效。
⚠️ 注意: 改完以后,Windows 时钟显示时会自动加时区偏移,大多数情况下正常。但某些老版本 Windows 和部分软件对 RTC=UTC 支持有问题,可能出现时间显示异常。所以一般推荐改 Linux 这边而不是改 Windows。
五、时区设置
顺便把时区对一对。
# 查看当前时区
timedatectl
# 列出所有时区
timedatectl list-timezones | grep Asia
# 设置为上海时区(东八区)
sudo timedatectl set-timezone Asia/Shanghai
# 验证
date
# 应输出类似:Wed Jun 17 09:00:00 CST 2026
常用时区参考:
| | |
|---|
Asia/Shanghai | | |
Asia/Taipei | | |
Asia/Tokyo | | |
America/New_York | | |
Europe/London | | |
六、NTP 自动对时
时区对了还不够,还要让系统自动和网络时间服务器同步,防止时间慢慢跑偏。
查看 NTP 状态
timedatectl
# 看这两行:
# System clock synchronized: yes ← 已同步
# NTP service: active ← 服务运行中
启用 NTP(如果没开)
# 启用 NTP 自动同步
sudo timedatectl set-ntp true
# 如果该命令报错,说明系统使用 ntp 或 chrony 服务,手动启用:
sudo systemctl enable systemd-timesyncd
# 验证
timedatectl show | grep NTP
Ubuntu 的 NTP 服务是 systemd-timesyncd
Ubuntu 默认用 systemd-timesyncd 做 NTP 同步,轻量但够用:
# 查看 timesyncd 状态
systemctl status systemd-timesyncd
# 查看同步日志
journalctl -u systemd-timesyncd -n 20
如果同步失败,检查一下 NTP 服务器配置:
cat /etc/systemd/timesyncd.conf
[Time]
NTP=ntp.aliyun.com ntp.tencent.com ntp1.aliyun.com
FallbackNTP=0.ubuntu.pool.ntp.org
💡 提示: 国内用 ntp.aliyun.com(阿里云)或 ntp.tencent.com(腾讯云)速度最快最稳定。默认的 pool.ntp.org 在国内有时访问不稳定。
修改 NTP 服务器:
sudo nano /etc/systemd/timesyncd.conf
# 修改 NTP= 那一行,改成国内服务器
# 保存后重启服务
# 如果该文件不存在,说明系统使用其他NTP服务(如 ntp 或 chrony),用 systemctl status ntp 查看。
sudo systemctl restart systemd-timesyncd
手动强制同步一次
# 停止 timesyncd,手动同步
sudo systemctl stop systemd-timesyncd
sudo apt install ntpdate # 某些发行版需安装ntpdate
sudo ntpdate ntp.aliyun.com
sudo systemctl start systemd-timesyncd
七、Windows 端检查时间服务
如果 Windows 那边时间也对不准,检查 Windows 的时间同步设置:
图形界面路径:
命令行方式(管理员 CMD):
cmd
:: 查看 Windows 时间服务状态
w32tm /query /status
:: 手动同步
w32tm /resync /force
:: 指定 NTP 服务器(可选)
w32tm /config /manualpeerlist:"ntp.aliyun.com" /syncfromflags:manual /reliable:YES /update
net stop w32time
net start w32time
w32tm /resync
八、完整修复流程
遇到双系统时间不同步,按这个顺序来:
| | |
|---|
| timedatectl 看 RTC in local TZ 是 yes 还是 no | |
| Linux 端执行 sudo timedatectl set-local-rtc 1 --adjust-system-clock | |
| sudo timedatectl set-timezone Asia/Shanghai | |
| sudo timedatectl set-ntp true | |
| 编辑 /etc/systemd/timesyncd.conf | |
| | |
九、常见问题速查
| | |
|---|
| | sudo timedatectl set-local-rtc 1 --adjust-system-clock |
| | sudo timedatectl set-timezone Asia/Shanghai |
NTP service: inactive | | sudo timedatectl set-ntp true |
| | |
| | w32tm /resync /force |
| | |
总结
| |
|---|
| Windows 存本地时间,Linux 存 UTC,差了一个时区偏移 |
| Linux 端一条命令:sudo timedatectl set-local-rtc 1 --adjust-system-clock |
| sudo timedatectl set-timezone Asia/Shanghai |
| sudo timedatectl set-ntp true |
如果改了时间还是不对,检查Windows是否开启了‘快速启动’,关闭后再试。
如果每次开机时间都回到同一个值,先检查主板纽扣电池。
💡 提示: 这个问题修一次就解决了,如果没有重装系统就不需要反复操作。核心就一条命令,不要被本篇的篇幅吓到——那些都是背景知识,帮你搞清楚为什么会这样。
📌 下一篇预告: 《Linux/windows双系统引导修复(上)——GRUB为什么被干掉了》,装 Windows 更新或重装 Windows 后 Linux 启动项消失了怎么办。