如何解决 Windows-Linux 双启动设置中显示时间错误的问题
时间 双启动 时钟
![](/data/attachment/album/202104/08/102102xaup3iofozn2uvbf.jpg)


如果你 [双启动 Windows 和 Ubuntu](https://itsfoss.com/install-ubuntu-1404-dual-boot-mode-windows-8-81-uefi/) 或任何其他 Linux 发行版，你可能会注意到两个操作系统之间的时间差异。


当你 [使用 Linux](https://itsfoss.com/why-use-linux/) 时，它会显示正确的时间。但当你进入 Windows 时，它显示的时间是错误的。有时，情况正好相反，Linux 显示的是错误的时间，而 Windows 的时间是正确的。


特别奇怪的是，因为你已连接到互联网，并且已将日期和时间设置为自动使用。


别担心！你并不是唯一一个遇到这种问题的人。你可以在 Linux 终端上使用以下命令来解决这个问题：



```
timedatectl set-local-rtc 1

```

同样，不要担心。我会解释为什么你在双启动设置中会遇到时间差。我会向你展示上面的命令是如何修复 Windows 双启动后的时间错误问题的。


### 为什么 Windows 和 Linux 在双启动时显示不同的时间？


一台电脑有两个主要时钟：系统时钟和硬件时钟。


硬件时钟也叫 RTC（[实时时钟](https://www.computerhope.com/jargon/r/rtc.htm)）或 CMOS/BIOS 时钟。这个时钟在操作系统之外，在电脑的主板上。即使在你的系统关机后，它也会继续运行。


系统时钟是你在操作系统内看到的。


当计算机开机时，硬件时钟被读取并用于设置系统时钟。之后，系统时钟被用于跟踪时间。如果你的操作系统对系统时钟做了任何改变，比如改变时区等，它就会尝试将这些信息同步到硬件时钟上。


默认情况下，Linux 认为硬件时钟中存储的时间是 UTC，而不是本地时间。另一方面，Windows 认为硬件时钟上存储的时间是本地时间。这就是问题的开始。


让我用例子来解释一下。


你看我在加尔各答 UTC+5:30 时区。安装后，当我把 [Ubuntu 中的时区](https://itsfoss.com/change-timezone-ubuntu/) 设置为加尔各答时区时，Ubuntu 会把这个时间信息同步到硬件时钟上，但会有 5:30 的偏移，因为对于 Linux 来说它必须是 UTC。


假设加尔各答时区的当前时间是 15:00，这意味着 UTC 时间是 09:30。


现在当我关闭系统并启动到 Windows 时，硬件时钟有 UTC 时间（本例中为 09:30）。但是 Windows 认为硬件时钟已经存储了本地时间。因此，它改变了系统时钟（应该显示为 15:00），而使用 UTC 时间（09:30）作为本地时间。因此，Windows 显示时间为 09:30，这比实际时间（我们的例子中为 15:00）早了 5:30。


![](/data/attachment/album/202104/08/102110ur1v5rn33a5z131l.jpg)


同样，如果我在 Windows 中通过自动时区和时间按钮来设置正确的时间，你知道会发生什么吗？现在它将在系统上显示正确的时间（15:00），并将此信息（注意图片中的“同步你的时钟”选项）同步到硬件时钟。


如果你启动到 Linux，它会从硬件时钟读取时间，而硬件时钟是当地时间（15:00），但由于 Linux 认为它是 UTC 时间，所以它在系统时钟上增加了 5:30 的偏移。现在 Linux 显示的时间是 20:30，比实际时间超出晚了 5:30。


现在你了解了双启动中时差问题的根本原因，是时候看看如何解决这个问题了。


### 修复 Windows 在 Linux 双启动设置中显示错误时间的问题


有两种方法可以处理这个问题：


* 让 Windows 将硬件时钟作为 UTC 时间
* 让 Linux 将硬件时钟作为本地时间


在 Linux 中进行修改是比较容易的，因此我推荐使用第二种方法。


现在 Ubuntu 和大多数其他 Linux 发行版都使用 systemd，因此你可以使用 `timedatectl` 命令来更改设置。


你要做的是告诉你的 Linux 系统将硬件时钟（RTC）作为本地时间。你可以通过 `set-local-rtc` （为 RTC 设置本地时间）选项来实现：



```
timedatectl set-local-rtc 1

```

如下图所示，RTC 现在使用本地时间。


![](/data/attachment/album/202104/08/102111gzvrupq2e2yogavg.png)


现在如果你启动 Windows，它把硬件时钟当作本地时间，而这个时间实际上是正确的。当你在 Linux 中启动时，你的 Linux 系统知道硬件时钟使用的是本地时间，而不是 UTC。因此，它不会尝试添加这个时间的偏移。


这就解决了 Linux 和 Windows 双启动时的时差问题。


你会看到一个关于 RTC 不使用本地时间的警告。对于桌面设置，它不应该引起任何问题。至少，我想不出有什么问题。


希望我把事情给你讲清楚了。如果你还有问题，请在下面留言。




---


via: <https://itsfoss.com/wrong-time-dual-boot/>


作者：[Abhishek Prakash](https://itsfoss.com/author/abhishek/) 选题：[lujun9972](https://github.com/lujun9972) 译者：[geekpi](https://github.com/geekpi) 校对：[wxy](https://github.com/wxy)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
![Warp Terminal](/assets/images/warp-terminal.webp)


![Warp Terminal](/assets/images/warp-terminal.webp)

If you [dual boot Windows and Ubuntu](https://itsfoss.com/install-ubuntu-1404-dual-boot-mode-windows-8-81-uefi/) or any other Linux distribution, you might have noticed a time difference between the two operating systems.

When you [use Linux](https://itsfoss.com/why-use-linux/), it shows the correct time. But when you boot into Windows, it shows the wrong time. Sometimes, it is the opposite and Linux shows the wrong time and Windows has the correct time.

That’s strange specially because you are connected to the internet and your date and time is set to be used automatically.

Don’t worry! You are not the only one to face this issue. You can fix it by using the following command in the Linux terminal:

`timedatectl set-local-rtc 1`


Again, don’t worry. I’ll explain in detail how the above command fixes the wrong time issue in Windows after dual boot. But before that, let me tell you why you encounter a time difference in a dual boot setup.

## Why Windows and Linux show different time in dual boot?

A computer has two main clocks: a system clock and a hardware clock.

A hardware clock which is also called RTC ([real time clock](https://www.computerhope.com/jargon/r/rtc.htm)) or CMOS/BIOS clock. This clock is outside the operating system, on your computer’s motherboard. It keeps on running even after your system is powered off.

The system clock is what you see inside your operating system.

When your computer is powered on, the hardware clock is read and used to set the system clock. Afterwards, the system clock is used for tracking time. If your operating system makes any changes to system clock, like changing time zone etc, it tries to sync this information to the hardware clock.

By default, Linux assumes that the time stored in the hardware clock is in UTC, not the local time. On the other hand, Windows thinks that the time stored on the hardware clock is local time. That’s where the trouble starts.

Let me explain with examples.

You see I am in Kolkata time zone which is UTC+5:30. After installing, when I set the [timezone in Ubuntu](https://itsfoss.com/change-timezone-ubuntu/) to the Kolkata time zone, Ubuntu syncs this time information to the hardware clock but with an offset of 5:30 because hardware clock (RTC) has to be in UTC for Linux.

Let’ say the current time in Kolkata timezone is 15:00 which means that the UTC time is 09:30.

Now when I turn off the system and boot into Windows, the hardware clock has the UTC time (09:30 in this example). But Windows thinks the hardware clock has stored the local time. And thus it changes the system clock (which should have shown 15:00) to use the UTC time (09:30) as the local time. And hence, Windows shows 09:30 as the time which is 5:30 hours behind the actual time (15:00 in this example).

![set time windows](https://itsfoss.com/content/images/wordpress/2021/03/set-time-windows-800x491.jpg)

Again, if I set the correct time in Windows by toggling the automatic time zone and time buttons, you know what is going to happen? Now it will show the correct time on the system (15:00) and sync this information (notice the “Synchronize your clock” option in the image) to the hardware clock.

If you boot into Linux, it reads the time from the hardware clock which is in local time (15:00) but since Linux believes it to be the UTC time, it adds an offset of 5:30 to the system clock. Now Linux shows a time of 20:30 which is 5:30 hours ahead of the actual time.

Now that you understand the root cause of the time difference issues in dual boot, it’s time to see how to fix the issue.

## Fixing Windows Showing Wrong Time in a Dual Boot Setup With Linux

There are three ways you can go about handling this issue:

- Make both Ubuntu and Windows check for date, time and timezone automatically via internet
- Make Linux use local time for the hardware clock
- Make Windows use UTC time for the hardware clock

I’ll discuss two of them which are easier.

### Method 1: Make your OS set time and date automatically

What happens in this case is that though your operating system (be it Windows or Linux) will show the incorrect time for a minute, and then it automatically sets the correct time if you are connected to the internet.

To make your Ubuntu Linux system check for date and time automatically, go to System Settings -> Date & Time and enable both options.

![set auto time date timezone ubuntu](https://itsfoss.com/content/images/wordpress/2022/03/set-auto-time-date-timezone-ubuntu-800x678.png)

You should do a similar settings change for Windows as well.

### Method 2: Make Ubuntu use local time for hardware clock

It is easier to make the changes in Linux and hence I’ll recommend going with the second method.

Ubuntu and most other Linux distributions use systemd these days and hence you can use timedatectl command to change the settings.

What you are doing is to tell your Linux system to use the local time for the hardware clock (RTC). You do that with the `set-local-rtc`

(set local time for RTC) option:

`sudo timedatectl set-local-rtc 1`


As you can notice in the image below, the RTC now uses the local time.

![Set local time for RTC in Ubuntu](https://itsfoss.com/content/images/wordpress/2021/03/set-local-time-for-rtc-ubuntu-800x490.png)

Now if you boot into Windows, it takes the hardware clock to be as local time which is actually correct this time. When you boot into Linux, your Linux system knows that the hardware clock is using local time, not UTC. And hence, it doesn’t try to add the off-set this time.

This fixes the time difference issue between Linux and Windows in dual boot.

You see a warning about not using local time for RTC. For desktop setups, it should not cause any issues. At least, I cannot think of one.

I hope I made things clear for you. If you still have questions, please leave a comment below.