398

Dual boot system Windows XP Pro and Ubuntu 12.04.

I have the bios set for the correct time and Ubuntu set for US Eastern time. Ubuntu will boot up and the time will be off by -4 hours. If I correct the time in Ubuntu then when I boot up in Windows XP the time will be off by + 4 hours.

This is a fresh install of 12.04. I did not have this problem before reinstalling Ubuntu.

zahypeti
  • 317
Bill Walden
  • 3,981

6 Answers6

372

https://help.ubuntu.com/community/UbuntuTime#Multiple_Boot_Systems_Time_Conflicts

Multiple Boot Systems Time Conflicts

Operating systems store and retrieve the time in the hardware clock located on your motherboard so that it can keep track of the time even when the system does not have power. Most operating systems (Linux/Unix/Mac) store the time on the hardware clock as UTC by default, though some systems (notably Microsoft Windows) store the time on the hardware clock as the 'local' time. This causes problems in a dual boot system if both systems view the hardware clock differently.

The advantage of having the hardware clock as UTC is that you don't need to change the hardware clock when moving between timezones or when Daylight Savings Time (DST) begins or ends as UTC does not have DST or timezone offsets.

Changing Linux to use local time is easier and more reliable than changing Windows to use UTC, so dual-boot Linux/Windows systems tend to use local time.

Since Intrepid (8.10), UTC=yes is default.

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, Server 2008 R2 and Windows 8/8.1.

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

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

Note: Windows Time service will still write local time to the RTC regardless of the registry setting above on shutdown, so it is handy to disable Windows Time service with this command (if time sync is still required while in Windows use any third-party time sync solution):

sc config w32time start= disabled

Reversing the change
You can create a file with the following contents and then double-click it to merge in the original changes, as above:

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

If Windows Time service was disabled, enable it again with the command:

sc config w32time start= demand

Make Linux use 'Local' time

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

Pre-Ubuntu 15.04 systems (e.g. Ubuntu 14.04 LTS):

  1. edit /etc/default/rcS
  2. add or change the following section

    # Set UTC=yes if your hardware clock is set to UTC (GMT)
    UTC=no
    

Ubuntu 15.04 systems and above (e.g. Ubuntu 16.04 LTS):

  1. open a terminal and execute the following command

    timedatectl set-local-rtc 1
    
muru
  • 197,895
  • 55
  • 485
  • 740
Eric Carvalho
  • 54,385
  • 86
    Oh lord. I can't believe they were dumb enough to use local time on a hardware clock. Why would you ever, ever do that? – iono Dec 09 '13 at 07:22
  • 33
    @twome because since there wasn't much in the way of networking in the early days of MS-DOS, and it wouldn't have been common to move a PC so far that it moved timezones. (And yeah, even considering that history, it was still not the best move). – Jon Hanna Apr 22 '14 at 13:44
  • 14
    @twome although I agree with you re hardware clock staying as Universal, since it doesn't keep timezone information, there are few problems with that: A) BIOS/UEFI have various features such as auto-wake up/sleep timers, where you set times for those triggers. It'd be weird to set those times in UTC - at least for average user. B) As Jon said above, backward compatibility reasons. – Gelmir May 15 '14 at 19:19
  • 13
    In Windows PowerShell run this command to update the above mentioned registry property: New-ItemProperty -Path HKLM:\SYSTEM\CurrentControlSet\Control\TimeZoneInformation -Name RealTimeIsUniversal -PropertyType DWord -Value 00000001 – Anatoly Mironov Jan 14 '15 at 09:29
  • 1
    When I tried to change that reg setting in Win7 I got: Cannot import [key]: Not all data was successfully written to the registry. Some keys are open by the system or other processes. Changed it in Ubuntu then. – pileofrocks Mar 16 '15 at 08:56
  • So far I've been fixing this problem by just running (as admin) a batch file to update the clock: https://gist.github.com/thedom85/dbeb58627adfb3d5c3af – mathandy Jun 03 '17 at 00:48
  • The upvoted comments here criticizing Microsoft's decision to use local time have made me concerned there's some reason I shouldn't set Ubuntu to use local time. Is there? – mathandy Jun 03 '17 at 00:50
  • 20
    For those skimming the text, you only have to change settings in one of the OSes, not both. – Alexander Revo Aug 08 '17 at 19:29
  • running timedatectl set-local-rtc 1 on ubuntu 18.04 didn't help for me. Do i need to restart? I mean the clock at the top of the screen is still wrong – cryanbhu Jul 25 '19 at 03:20
  • 1
    What worked for me was only the registry fix, not the sc command (Windows 10). Linux Mint unchanged. – Sony Santos Apr 04 '20 at 07:47
  • i have the same problem but i noticed that Bios has the wrong time that the windows10 displays (only after i had previously booted in Linux). I tried changing the Bios time but when i go back it's the false one every time... – Panagiss Oct 16 '20 at 08:53
  • Note that 'info timedatectl' specifically warns AGAINST doing this. "Note that maintaining the RTC in the local timezone is not fully supported and will create various problems with time zone changes and daylight saving adjustments. If at all possible, keep the RTC in UTC mode." – Die in Sente Nov 19 '20 at 15:05
  • Should this change the time instantly? My time is off by an hour after using Windows 10 but timedatectl set-local-rtc 1 or timedatectl set-local-rtc 0 does not make any difference. – Kvothe Feb 17 '21 at 11:28
  • 1
    The reason for this mess is "historical reasons". MS-DOS design used only BIOS clock and it didn't even understand the concept of timezone or daylight saving time. Windows 3.11 had to be compatible with the same filesystem so it used local time, too. When Windows 95 and NT were introduced, those were commonly used in dual boot systems with MS-DOS and had to be compatible, too. And Windows 11 wants still to be compatible with the chain of previous Windows versions up to MS-DOS. Change to UEFI would have been clear cut fix, but Intel failed to implement the fix there so UEFI time is local, too. – Mikko Rantalainen Nov 23 '21 at 15:04
  • 1
    I still don't understand why "BIOS clock uses UTC" is not a checkbox option in Windows time settings today. Windows has major problems with daylight saving time when you dual boot just between multiple Windows versions today. The only case where "BIOS is local time" somewhat works is if your computer only uses one OS and doesn't need to handle multiple timezones. – Mikko Rantalainen Nov 23 '21 at 15:06
  • For Windows 10, the command to disable Windows Time should be

    Set-Service -Name "W32Time" -Status stopped -StartupType disabled

    – navjotjsingh Oct 25 '23 at 08:54
80

To set the BIOS clock to local time instead of UTC in a systemd-based version (15.04 and above), you will have to use the timedatectl command. According to the Arch Wiki:

You can set the hardware clock time standard through the command line. You can check what you have set to use by:

$ timedatectl | grep local

The hardware clock can be queried and set with the timedatectl command. To change the hardware clock time standard to localtime, use:

# timedatectl set-local-rtc 1

If you want to revert to the hardware clock being in UTC, do:

# timedatectl set-local-rtc 0
muru
  • 197,895
  • 55
  • 485
  • 740
  • 5
    On Ubuntu 16.10 it helped to do "hwclock --systohc --localtime". This writes the "local part" to /etc/adjtime and thereby makes it permanent. – user1050755 Oct 21 '16 at 19:25
  • 3
    @user1050755 is that before, after, or instead of the timedatectl command? – nasch Jan 16 '18 at 00:45
  • For me too, on Antix-Core-22, only hwclock --systohc --localtime worked! After that, I changed the clock on the BIOS, and voilà! – Pedro Siqueira Mar 06 '23 at 18:32
39

Your time zone is Eastern, which is currently EDT (Eastern Daylight Time). EDT is UTC minus four hours, the same as the offset you're experiencing.

When this happens on a dual-boot system, it's usually because one operating system thinks the hardware clock tracks local time, while the other operating system thinks the hardware clock tracks UTC.

In your case, your hardware clock is probably set to the local time, and:

  • Windows is set to use local time, which (given your time settings) is correct.
  • Ubuntu is set to use UTC, which (given your time settings) is incorrect.

If you were to just reset the time in the Ubuntu system, either manually or automatically, it would then be wrong in Windows, so that's not a good solution.

Instead, the best solution is probably to reconfigure Ubuntu to treat the hardware clock time as local time (then you can leave your Windows configuration, and your hardware clock time, alone).

To do this, edit /etc/default/rcS as root and make sure it has UTC=no:

  1. Press Alt+F2.

  2. Type gksu gedit /etc/default/rcS and press Enter.

  3. You'll probably see this:

    # assume that the BIOS clock is set to UTC time (recommended)
    UTC=yes
    
    • If you do, change UTC=yes to UTC=no. (Or you might want to add a comment too, by changing it to something like UTC=no # changed to accommodate Windows system. Everything on a line after a # character is a comment, and is there just to make your settings more human-readable.)
    • If you don't, look for any UTC= line. If it's uncommented (i.e., doesn't have a # at the beginning), change it accordingly. If it is commented, uncomment it by removing the leading # and make sure it says UTC=no.
  4. Save the file and quit the text editor.

  5. Reboot to apply your changes and check that the time is working properly now on both operating systems.

Source: https://help.ubuntu.com/community/UbuntuTime#Make_Linux_use_.27Local.27_time

(But that is very general; I have written this answer to apply specifically to your situation, which is a somewhat common problem.)

Eliah Kagan
  • 117,780
  • Note that this can also occur when you upgrade from one Ubuntu release to the next, like it did for me. I can recommend performing the above fix, and then also manually syncing your clock as in this answer (adjusting it to work with systemd): http://askubuntu.com/a/254846/139735 – starbeamrainbowlabs Jun 20 '16 at 20:03
  • This should be the accepted answer imho. I had Windows installed and running fine, then I installed Ubuntu and the clocks went haywire - I can't see a reason why I should modify Windows settings if it was clearly the addition of linux that broke my configuration. – Przemek D Apr 18 '18 at 08:03
  • 1
    @PrzemekD That's kind of arbitrary though. I had Linux installed and running fine, then I installed Windows and the clocks went haywire. They just disagree on whether hardware clocks should be in local time or in UTC. – Ullallulloo Aug 07 '21 at 21:32
  • @Ullallulloo You might be right, I am a lifelong Windows user and looking from Windows-centric perspective. – Przemek D Aug 16 '21 at 15:52
15

The /etc/rcS fix did not work on my Win7 / Ubuntu 14.04x64 installation, nor did any fixes through the clock GUI. Because the root of the problem is BIOS time VS UTC time, and Windows is a pain in the butt when it comes to using UTC, I just picked a point on the map that uses UTC+0 (no change between BIOS and UTC time).

Try changing your location to Reykjavik (the capital of Iceland). Voila! Your Ubuntu time will change to match your BIOS time.

3

I had 1h of difference on each time I boot into linux or windows. It's because one is on UTC ant the other one in RTC

To fix my ubuntu 20.04 I used this:

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

in my case to go back to UTC you can

timedatectl set-local-rtc 0 --adjust-system-clock

and if you want to check what you're using you can type that: timedatectl

Fl_ori4n
  • 146
2

enter image description here

We can ask Windows to sync time with the network on every reboot:

  1. Search for "Services" from the start menu.
  2. Locate "Windows Time".
  3. Set "Startup type" to "Automatic". In my case, the time updates at about 10 seconds after logging in to Windows.

On Ubuntu, we can set "Automatic Date & Time" in settings, and by default, it runs on every reboot automatically.

This is my favorite approach as it does not require modifying the registry or setting Linux to use "local" time, which might have side effects such as daylight saving time synchronization.

See this answer and this answer for more reference.

  • 1
    The problem with this is that your logs will have the incorrect time between boot and sync as this will change the bios time every time you change OS. This could cause issues with applications as well – rtaft Sep 27 '21 at 19:34