欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

解决Windows和Linux双系统时间不一致的问题

程序员文章站 2022-07-14 17:04:54
...

默认情况下 Windows 认为 BIOS 时间为本地时间,而 Linux 则认为 BIOS 时间为 UTC 时间。因此在进行双系统切换后往往导致时间差几个小时的问题。下面是两种方案,任选其一即可。

Make Windows use UTC

Note: This method was not initially supported on Windows Vista and Server 2008, but came back with Vista SP2, Windows 7 and Server 2008 R2.

To make MS Windows calculate the time from the hardware clock as UTC.

Via regedit:

Run regedit and navigate to

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation

Right-click in the right-side panel and select New > DWORD Value. Create the key named RealTimeIsUniversal and give it a value of 1.

Using a registry file

Create a file named WindowsTimeFixUTC.reg with the following contents and then double click on it to merge the contents with the registry:

Windows Registry Editor Version 5.00
 
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation]
"RealTimeIsUniversal"=dword:00000001

Make Linux use ‘Local’ time

To tell your Ubuntu system that the hardware clock is set to ‘local’ time:

  1. edit /etc/default/rcS

  2. Set UTC=yes if your hardware clock is set to UTC (GMT), or UTC=no to have the hardware clock set to local time.

It’s come to my attention that this issue also affects Macs which dual boot via bootcamp or other methods.

Reference

https://mikebeach.org/2011/04/10/windows-linux-dual-boot-system-time-issues/

补充

Ubuntu 16.04 使用 systemd 启动之后,时间也改成了由 timedatectl 来管理,而时间同步也由 timedatectl 进行管理,不再使用 ntpdate。改为执行:

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

https://www.cnblogs.com/EasonJim/p/8111832.html