timsta97 Posted September 2, 2010 Share Posted September 2, 2010 My computer clock is always about 6 minutes off, and when I reset it goes back eventually. I created a script that would set the clock for me, so I wouldn't have to keep setting it by hand, but the hour gets set to about five hours earlier. If @HOUR + 5 is greater than 23, it doesn't set the clock at all. What am I doing wrong? #include <Date.au3> $tCur = _Date_Time_GetSystemTime() $min = @MIN + 6 $hour = @HOUR if $min > 59 Then $min = $min - 59 $hour = $hour + 1 EndIf $tNew = _Date_Time_EncodeSystemTime(@MON, @MDAY, @YEAR, $hour, $min, @SEC, @MSEC) _Date_Time_SetSystemTime(DllStructGetPtr($tNew)) Link to comment Share on other sites More sharing options...
4Eyes Posted September 2, 2010 Share Posted September 2, 2010 timsta97, Firstly, _Date_Time_GetSystemTime() gets time in UTC format. Depending on where you are in the world that could be spot on or more likely way off. While not even bothering to check, I'd say that if $hour > 23 then _Date_Time_EncodeSystemTime() is going to fail. Next, if your pc's time drifts slowly, what's the point of adjusting it by 6 minutes when you don't know what the real time is? A really poor alternative would be to use _NowTime() and 'adjust' the time from there. Best solution would be to use an Internet time source or a program designed to do this. Good luck finding a reliable NTP server if you want to do it yourself. 4Eyes Link to comment Share on other sites More sharing options...
wakillon Posted September 2, 2010 Share Posted September 2, 2010 Why do you not try to synchronize your clock ? AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts Link to comment Share on other sites More sharing options...
timsta97 Posted September 2, 2010 Author Share Posted September 2, 2010 Why do you not try to synchronize your clock ?The problem is in the synchronization of my clock. My school's network clock is off by six minutes, so every time I synchronize, it changes the clock back. I just want the little script on my desktop to click whenever it synchronizes.I accidentally left $tCur = _Date_Time_GetSystemTime() in the code; it isn't necessary, so I got rid of it. Link to comment Share on other sites More sharing options...
timsta97 Posted September 2, 2010 Author Share Posted September 2, 2010 I stumbled across _Date_Time_Format(). Can I use this to correct the time? Link to comment Share on other sites More sharing options...
Valuater Posted September 2, 2010 Share Posted September 2, 2010 There are many approaches to this issue.First, here is a thread full of time related code...http://www.autoitscript.com/forum/index.php?showtopic=112854&st=0&p=790414&hl=time%20valuater&fromsearch=1&#entry790414ALWAYS... "BE SURE TO SEARCH FIRST"Secondly, If @HOUR + 5 is greater than 23, it doesn't set the clock at all. What am I doing wrong?On a 24 hour clock it goes from 23:59 to 00:00. The hour is never greater than 238) Link to comment Share on other sites More sharing options...
timsta97 Posted September 2, 2010 Author Share Posted September 2, 2010 Thanks for the help everybody, but I figured it out. I used _Date_Time_SetLocalTime() instead of _Date_Time_SetSystemTime(). Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now