Sign in to follow this  
Followers 0
timsta97

Date Time Error

7 posts in this topic

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))

Share this post


Link to post
Share on other sites



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

Share this post


Link to post
Share on other sites

Why do you not try to synchronize your clock ?


AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

I stumbled across _Date_Time_Format(). Can I use this to correct the time?

Share this post


Link to post
Share on other sites

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&#entry790414

ALWAYS... "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 23

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

Thanks for the help everybody, but I figured it out. I used _Date_Time_SetLocalTime() instead of _Date_Time_SetSystemTime().

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
Sign in to follow this  
Followers 0