Jump to content
harmc0re

Fix the time difference between osx86 and Windows in multiboot setups.

41 posts in this topic

Recommended Posts

Fix the time difference between osx86 and
Windows in multiboot setups.

Preface: When you installed osx86, dual-booting with Windows,
you might notice your clock changed one or several hours
when booting Windows right after osx86 and vice versa.

Why does this happen? Macs save the universal time (aka UTC)
of the world to the BIOS instead of the local time
of the time zone you live in (aka localtime).
And Windows assumes the BIOS time is the local time.

Wait, what? For instance, while running osx86,
the clock on your screen could read 4:02pm (local time),
but in your BIOS, the time could be 2:02pm (universal time).
And if you would reboot to Windows, the clock in the taskbar
will read 2:02pm because Windows reads the time from
the BIOS upon booting and assumes it's the local time.

How can we fix this? The best way to fix this, in my opinion, is to make an
adjustment to the osx86 installation, and not to your Windows OS because
that's not where the problem is located, and on the other hand,
I believe it's only logical that your BIOS time reflects your local time.
In other words, we will create a script and a launchdaemon for your osx86 installation
to switch between UTC and localtime every time you run osx86.
This fix is tested and confirmed working on OS X 10.5.x - 10.9.x. (it might work on older versions of OS X though, but I can't test it.)

The scripts are made in plain text, to configure TextEdit to create plain text files, open up TextEdit's preferences window, and click "Plain text".
Just like in this screenshot.

Or just use nano or vi if you're familiar with those. Whichever floats your boat.

1. First, we will make the script.
Create a file named localtime-toggle and place it in /sbin.


#!/bin/sh

to_utc() {
	echo "localtime-toggle: Toggling to UTC."
	date -f %m%d%H%M%Y `date -u +%m%d%H%M%Y`
}

to_localtime() {
	echo "localtime-toggle: Toggling to localtime."
	date -u -f %m%d%H%M%Y `date +%m%d%H%M%Y`
}

trap 'to_localtime; exit' term
to_utc
{ while true; do sleep 86400; done; } &
wait
 
2. Second, we will write the launchdaemon.
Create a file named org.osx86.localtime-toggle.plist
and place it in /System/Library/LaunchDaemons.


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>Label</key>
	<string>org.osx86.localtime-toggle</string>
	<key>Program</key>
	<string>/sbin/localtime-toggle</string>
	<key>KeepAlive</key>
	<true/>
	<key>RunAtLoad</key>
	<true/>
	<key>HopefullyExitsFirst</key>
	<true/>
</dict>
</plist>
 
3. Now, we have to execute some commands.
The first command makes our script executable:
sudo chmod +x /sbin/localtime-toggle

The second and third command will give our launchdaemon the right permissions:
sudo chown root /System/Library/LaunchDaemons/org.osx86.localtime-toggle.plist
sudo chmod 644 /System/Library/LaunchDaemons/org.osx86.localtime-toggle.plist

The final command will load our launchdaemon.
sudo launchctl load -w /System/Library/LaunchDaemons/org.osx86.localtime-toggle.plist

Now, if all went well, upon pressing enter on that last command, you should notice the time changed again.
If not, you did something wrong.
Don't worry,
check if the scripts you made are correct, if they are plain-text,

and if they have the correct names and places.
Also, press up in the terminal to see the history of commands you pressed, and check if they are correct.


4. Sync the clock with the internet, or manually correct the time, and you're done! :)
Finally, a few notes: I made this guide because there are a few different ways described on the internet that deal with this problem, but I think they are hard to find or incomplete.

I took some time and effort to write this, so if...
this solved your problem,
this didn't solve your problem,
I made any mistakes on the grammar or the technical side,
please write a comment to let me know.


Harm.
Edited by harmc0re

Share this post


Link to post
Share on other sites
Advertisement

This works thanks sooo much! I changed locations of the script (/usr/local/sbin) and the launchdaemon (/Library/LaunchDaemons) in my installation of your scripts. but other than after running your scripts to boot into windows 7, the time was correct and then back into Lion and it works 100% so far :unsure:

 

I do notice two running instances/processes of the localtime-toggle script though, is that normal?

 

$ ps -ef | grep localtime-toggle
   0    76     1   0  4:00PM ??         0:00.01 /bin/sh /usr/local/sbin/localtime-toggle
   0    88    76   0 11:00PM ??         0:00.00 /bin/sh /usr/local/sbin/localtime-toggle

Share this post


Link to post
Share on other sites
This works thanks sooo much! I changed locations of the script (/usr/local/sbin) and the launchdaemon (/Library/LaunchDaemons) in my installation of your scripts. but other than after running your scripts to boot into windows 7, the time was correct and then back into Lion and it works 100% so far :)

 

I do notice two running instances/processes of the localtime-toggle script though, is that normal?

 

$ ps -ef | grep localtime-toggle
   0    76     1   0  4:00PM ??         0:00.01 /bin/sh /usr/local/sbin/localtime-toggle
   0    88    76   0 11:00PM ??         0:00.00 /bin/sh /usr/local/sbin/localtime-toggle

Same here, ronsega:

 

Harm-Claeyss-HackBook-Pro:~ harm$ ps -ef | grep localtime-toggle
   0  1690     1   0   0:00.01 ??         0:00.01 /bin/sh /sbin/localtime-toggle
   0  1740  1690   0   0:00.00 ??         0:00.00 /bin/sh /sbin/localtime-toggle
 501 54358 53986   0   0:00.00 ttys000    0:00.00 grep localtime-toggle

 

Thanks to let me know, I don't know why there are two instances though...

Share this post


Link to post
Share on other sites

If you install Bootcamp drivers on your Windows hard drive it will fix that and allow you to see your HFS drives and your magic mouse will work too.

Share this post


Link to post
Share on other sites

im having trouble saving with the right file endings, i cant get it to save as a normal file or .plist correctly. also, when i did $ sudo chmod +x /sbin/localtime-toggle, it said -bash: $: command not found

Share this post


Link to post
Share on other sites
im having trouble saving with the right file endings, i cant get it to save as a normal file or .plist correctly. also, when i did $ sudo chmod +x /sbin/localtime-toggle, it said -bash: $: command not found

 

You need to leave out the $-signs and the extra space after that.

Sometimes people like to add a $ before a command to say "this is a Terminal command"

Sorry, I didn't want to confuse you.

 

If you enter these two commands in Terminal:

sudo cp /sbin/disklabel Desktop/localtime-toggle (Note that this command may ask for your password!)

cp Desktop/localtime-toggle Desktop/org.osx86.localtime-toggle.plist

 

There will be two extra files added to your desktop.

You can right-click on them and choose Open with -> Other...

Then choose TextEdit in the list.

You will see a lot of weird letters there, just delete all of them

Then you can type the things from my guide and save the files.

 

If you install Bootcamp drivers on your Windows hard drive it will fix that and allow you to see your HFS drives and your magic mouse will work too.

Oh, thanks, I didn't know that.

 

But still, in my opinion, I think it's better to fix this on the Mac OS X side.

And if you see my signature, you will see that I have 2 Windows OSes, so this remains the best solution for me.

 

 

... and allow you to see your HFS drives ...

Interesting, can you specify "see your HFS drives"?

Can you read the files on them, can you write files on them (even though the drives are Journaled)?

Share this post


Link to post
Share on other sites
If you install Bootcamp drivers on your Windows hard drive it will fix that and allow you to see your HFS drives and your magic mouse will work too.

Could you elaborate on as to how to do this.

 

Thanks

Share this post


Link to post
Share on other sites

Easiest fix I've found:

 

Boot into Windows.

Run --> Regedit

 

Browse to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation\

Check if a DWORD (32-Bit) called "RealTimeIsUniversal" exists. If it does, make sure its value "1". If it doesn't make a new DWORD (32-Bit) and call it "RealTimeIsUniversal" and have it set a value of 1.

 

Reboot into OS X.

Set the time via time.apple.com.

Reboot into Windows.

All should be well.

Share this post


Link to post
Share on other sites
Easiest fix I've found:

 

Boot into Windows.

Run --> Regedit

 

Browse to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation\

Check if a DWORD (32-Bit) called "RealTimeIsUniversal" exists. If it does, make sure its value "1". If it doesn't make a new DWORD (32-Bit) and call it "RealTimeIsUniversal" and have it set a value of 1.

 

Reboot into OS X.

Set the time via time.apple.com.

Reboot into Windows.

All should be well.

Are you kidding me? Have you read the guide?

 

... How can we fix this? The best way to fix this, is to make an adjustment to the osx86 installation,

and not to your Windows OS because that's not where the problem is located. ...

Okay, you can tell Windows to treat the bios time as UTC, or tell Mac to treat the bios time as localtime, it's just the same thing. But I rather apply a fix to the Mac OS, because that's where the problem started.

Share this post


Link to post
Share on other sites

Thanks for both the fixes. :D I've been too lazy to mess with it because I've been more concerned about getting the installs working properly but once I finish, this will be done.

Share this post


Link to post
Share on other sites
Are you kidding me? Have you read the guide?

What is the problem with it? I'm using this registry method for a year now, without any problem. Why scripting better, what are the benefits of it?

Share this post


Link to post
Share on other sites
You need to leave out the $-signs and the extra space after that.

Sometimes people like to add a $ before a command to say "this is a Terminal command"

Sorry, I didn't want to confuse you.

 

If you enter these two commands in Terminal:

sudo cp /sbin/disklabel Desktop/localtime-toggle (Note that this command may ask for your password!)

cp Desktop/localtime-toggle Desktop/org.osx86.localtime-toggle.plist

 

There will be two extra files added to your desktop.

You can right-click on them and choose Open with -> Other...

Then choose TextEdit in the list.

You will see a lot of weird letters there, just delete all of them

Then you can type the things from my guide and save the files.

 

i tried editing localtime-toggle, but it says i didnt have sufficient permission to save

Share this post


Link to post
Share on other sites
i tried editing localtime-toggle, but it says i didnt have sufficient permission to save

Oh, sorry about that.

Can you save org.osx86.localtime-toggle.plist?

If you do

 

sudo chmod 777 Desktop/localtime-toggle

 

and (only if you also have problems to save the org.osx86.localtime-toggle.plist file)

 

sudo chmod 777 Desktop/org.osx86.localtime-toggle.plist

 

And you should be able to edit and save them both then.

Share this post


Link to post
Share on other sites

My .05 cents worth.

 

I use the windows regedit trick.

As OS X is my main OS, it makes sense to leave it on Universal Time.

This works extremely well, having used it for quite some time.

 

It's all down to personal preference of course, but agree that regedit is way easier.

Share this post


Link to post
Share on other sites

I have two Windows OSes, so for me it makes sense to use this scripting method. :)

 

I don't see why people fiddle around in Windows to make the time in sync. :unsure:

Before the osx86 installation, the bios time is the localtime, so I think it should stay that way.

 

But that's just my opinion then.

Share this post


Link to post
Share on other sites
But still' date=' in my opinion, I think it's better to fix this on the Mac OS X side.[/quote'] Just my thought.

 

Thanks for the guide.

Share this post


Link to post
Share on other sites

Thanks. OP. Was looking for a fix on the OSX side forever. For everyone who keeps saying that the Windows Registry hack is the "better" way. You guys aren't fully correct. For people like me who use Windows Media Center with a TV tuner card, the windows registry fix is not a viable solution. It screws up the recording schedules. The only fix for people who use WMC, is the OSX fix.

Share this post


Link to post
Share on other sites

I think That I have found the easiest solution for this problem.

 

I think that the only thing you should do is change the time zone on your mac insallation.

 

Here is my example:

My mac was showing 17:00 o'clock instead of the 15:00, which was the time at the moment.

 

I'm living in time zone X and all I needed to do was to change it to X-2 time zone and lock the changes.

 

I've restarted my pc serveral times and both Windows and Mac are showing the right time.

 

I hope someone else is going to try this, in order to see if this really works.

 

 

 

 

 

Share this post


Link to post
Share on other sites

Yeah but now your time zone is wrong. This remains the best way because it eliminates the issue completely, with zero undesirable side effects.

 


Boot into Windows.
Run --> Regedit

Browse to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation\
Check if a DWORD (32-Bit) called "RealTimeIsUniversal" exists. If it does, make sure its value "1". If it doesn't make a new DWORD (32-Bit) and call it "RealTimeIsUniversal" and have it set a value of 1.

Reboot into OS X.
Set the time via time.apple.com.
Reboot into Windows.
All should be well.

 

...unless you count your BIOS clock now showing UTC as undesirable of course. But why would you.

Share this post


Link to post
Share on other sites

Before the osx86 installation, the bios time is the localtime, so I think it should stay that way.

I think people are missing his point here.  We are talking about a hackintosh here.  A PC whose BIOS is designed to have the time set in local time.  Macs are designed for UTC.  If you use the regedit fix, the time will be wrong in the BIOS and possibly cause other problems (like skim32's WMC problem).  Also be careful using bootcamp on a hackintosh.  It might screw up the boot sector of your Windows installation.  Keep in mind that bootcamp is designed for real Macs which use EFI boot.

Share this post


Link to post
Share on other sites

I just converted my work PC into a dual-boot Win7 and ML machine  :dev:.  The script and launchdaemon solved my annoying time difference.

 

Thanks harm! 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×