windows和linux双系统时间同步方案

在双系统下,主机的时间经常会发生混乱,windows以硬件时间为当前时区时间,而linux通常以硬件时间为utc时间,对于+8时区,两者相差8小时。如果以windows为主系统,可以在linux下做以下设置。

windows系统时间设置不做改动。

linux系统下设置

sudo timedatectl set-local-rtc 1 --adjust-system-clock

查看系统时间:
timedatectl
系统显示:

1
2
3
4
5
6
7
8
9
10
11
12
               Local time: 五 2025-03-21 18:07:50 CST
Universal time: 五 2025-03-21 10:07:50 UTC
RTC time: 五 2025-03-21 10:07:50
Time zone: Asia/Shanghai (CST, +0800)
System clock synchronized: yes
NTP service: active
warning: The system is configured to read the RTC time in the local time zone.
This mode cannot be fully supported. It will create various problems
with time zone changes and daylight saving time adjustments. The RTC
time is never updated, it relies on external facilities to maintain it.
If at all possible, use RTC in UTC by calling
'timedatectl set-local-rtc 0'.

第一次回windows同步一下时间,之后再切换系统,时间不再混乱。
再回linux:
timedatectl
系统显示:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
               Local time: 五 2025-03-21 18:34:59 CST
Universal time: 五 2025-03-21 10:34:59 UTC
RTC time: 五 2025-03-21 18:34:59
Time zone: Asia/Shanghai (CST, +0800)
System clock synchronized: no
NTP service: active
RTC in local TZ: yes

Warning: The system is configured to read the RTC time in the local time zone.
This mode cannot be fully supported. It will create various problems
with time zone changes and daylight saving time adjustments. The RTC
time is never updated, it relies on external facilities to maintain it.
If at all possible, use RTC in UTC by calling
'timedatectl set-local-rtc 0'.

此处RTC时间和CST时间一致。
改回缺省设置:
timedatectl set-local-rtc 0 #此处RTC时间是UTC时间。

不同linux系统时间处理命令不同,ubuntu上面的hwclock在deepin23上就没有,也不能apt安装。