Table of Contents
If you dual boot Windows and Ubuntu or any other Linux distribution, you might have noticed a time difference between the two operating systems.
When you 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.
Why Windows and Linux show different time in dual boot?
A computer has two main clocks
- A hardware clock which is also called RTC (real time clock) or CMOS/BIOS clock. This clock is outside the operating system, on your computer’s motherboard. It keeps on running even after your computer 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.
Fixing Windows Showing Wrong Time in a Dual Boot
There are two 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 your OS set time and date automatically
To make your Ubuntu Linux system check for date and time automatically, go to System Settings | Date & Time and enable both options.
You should do a similar settings change for Windows as well.
Make Ubuntu use local time for hardware clock
It is easier to make the changes in Linux and hence I’ll recommend going with this method.
Ubuntu and most other Linux distributions use systemd these days and hence you can use timedatectl command to change the settings.
# sudo timedatectl Local time: ស 2022-11-05 06:55:33 +07 Universal time: សុ 2022-11-04 23:55:33 UTC RTC time: សុ 2022-11-04 23:55:33 Time zone: Asia/Ho_Chi_Minh (+07, +0700) System clock synchronized: no NTP service: active RTC in local TZ: no
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:
timedatectl set-local-rtc 1
As you can see, the RTC now uses the local time.
# sudo timedatectl set-local-rtc 1 # sudo timedatectl Local time: សុ 2022-11-04 23:58:06 +07 Universal time: សុ 2022-11-04 16:58:06 UTC RTC time: សុ 2022-11-04 23:58:06 Time zone: Asia/Ho_Chi_Minh (+07, +0700) System clock synchronized: yes NTP service: active RTC in local TZ: yes
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.