Jump to content

set local time to internet timeserver time example script


jennico
 Share

Recommended Posts

my script pings 5 internet time servers and retrieves UTC time and date info from the fastest.

then sets local time to internet time using _Date_Time_SetLocalTime. delay is not yet included.

unfortunately, in my timezone the result is one hour earlier than it should be.

please everyone, run my script and tell me if you get the same result. The date, minute, second is correct, so don't worry. the worst that can happen is that you have to correct the hour afterwards.

Edit: Problem solved.

and maybe anyone (PaulIA ?) can give me an idea because it results wrong on my pc ? now is november and there is no daylight setting.

why is there an hour difference to my local settings ?

thx

j.

Edited by jennico
Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

Link to comment
Share on other sites

please help me to finish that, i will post it in example scripts for everyone.

j.

i just need feedback if the result is wrong all over the world or not !

Edited by jennico
Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

Link to comment
Share on other sites

It's not working right. It set my time back 4 hours.

EDIT: Don't wait for PaulIA. He hasn't been around the forums for well over a year now.

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

You have to use SetSystemTime, not SetLocalTime, because you will receive UTC time.

Alos, you should use _InetGetSource, because this is MUCH faster than getting page with IE.

Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

You have to use SetSystemTime, not SetLocalTime, because you will receive UTC time.

Alos, you should use _InetGetSource, because this is MUCH faster than getting page with IE.

SetSystemTime fixed it. I'm not sure why mine went back 4 hours though. I'm actually at UTC -8 hours.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Hmm, this is really strange ...

Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

Hmm, this is really strange ...

When you tried it before the modification, did your time only go back to (UTC - (offset/2))? That's half the difference between UTC and your TZ offset. It will be interesting to see if Jennico (went back 1 hour) is actually in the time zone at UTC - 2 hours.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

my script pings 5 internet time servers and retrieves UTC time and date info from the fastest.

then sets local time to internet time using _Date_Time_SetLocalTime. delay is not yet included.

unfortunately, in my timezone the result is one hour earlier than it should be.

please everyone, run my script and tell me if you get the same result. The date, minute, second is correct, so don't worry. the worst that can happen is that you have to correct the hour afterwards.

#include <IE.au3> 

Dim $server[5] = ["64.125.78.85","64.236.96.53","128.138.140.44","132.163.4.102","132.163.4.101"]
$best=0
$min=500

For $i=0 To 4
    $t=Ping($server[$i],500)
    If $t>0 And $t<$min Then $best=$i
Next

$oIE = _IECreate("http://"&$server[$best]&":13",0,0,1,-1)

;$start=TimerInit()

$data=StringSplit(_IEBodyReadText($oIE)," ")
$date=StringSplit($data[2],"-")
$time=StringSplit($data[3],":")

MsgBox(0, "UCT time found :",$date[2]&@CRLF&$date[3]&@CRLF&$date[1]&@CRLF& _
    $time[1]&@CRLF&$time[2]&@CRLF&$time[3]&@CRLF&$data[7])

$tSystemTime = DllStructCreate("short Year;short Month;short Dow;short Day;"& _
    "short Hour;short Minute;short Second;short MSeconds")
DllStructSetData($tSystemTime, "Month", $date[2])
DllStructSetData($tSystemTime, "Day", $date[3])
DllStructSetData($tSystemTime, "Year", "20"&$date[1])
DllStructSetData($tSystemTime, "Hour", $time[1])
DllStructSetData($tSystemTime, "Minute", $time[2])
DllStructSetData($tSystemTime, "Second", $time[3])
DllStructSetData($tSystemTime, "MSeconds", $data[7])

DllCall("Kernel32.dll", "int", "SetLocalTime", "ptr", DllStructGetPtr($tSystemTime))
DllCall("Kernel32.dll", "int", "SetLocalTime", "ptr", DllStructGetPtr($tSystemTime))

MsgBox(0,"Time changed","Is it correct ?")

Exit

and maybe anyone (PaulIA ?) can give me an idea because it results wrong on my pc ? now is november and there is no daylight setting.

why is there an hour difference to my local settings ?

thx

j.

Maybe you should add

_IEQuit ($oIE)

to the end of your test script to avoid having a hidden internet explorer left open.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

When you tried it before the modification, did your time only go back to (UTC - (offset/2))? That's half the difference between UTC and your TZ offset. It will be interesting to see if Jennico (went back 1 hour) is actually in the time zone at UTC - 2 hours.

Or Jennico is in a time zone UTC - 5 hours, so your PC's are treating UTC time like it's Atlantic time or something.
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

thank you all.

i am in central europe. so are we conform that "SetSytemTime" is correct ?

but what does "SetLocalTime" do then ? in helpfile it seems so that local is correct, and system does uct. maybe it is mixed up ?

thank you. i can complete my script now.

j.

Edit: SetSystemTime does not do it for me. still one hour too late. very rare.

i still have to increment the hour by one.

DllStructSetData($tSystemTime,"Hour",$time[1]+1)

this is very strange. i can't find the logic in it.

Edited by jennico
Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

Link to comment
Share on other sites

as for inetget, i will have to write it to a script, and then read it. this is slower than my method. iEnavigate is slower at the beginning, but once the page is completed, reading will be faster.

the time the page needs to build up does not matter. the delay after this is more important. and this will be bigger foe inetget. i think.

well, i calculated a delay of <4 ms for my method, so this is really irrelevant.

j.

edit: i just saw you meant _inetgetsource, i will do that. thanks.

Edited by jennico
Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

Link to comment
Share on other sites

> ProgAndy: "... you should use _InetGetSource, because this is MUCH faster ..."

> jennico: "as for inetget, i will have to write it to a script [you mean file?], and then read it. this is slower than my method. ... "

From the help file for _INetGetSource:

Gets the source from an URL without writing a temp file.

Does the OS that you are using not have an time auto sync feature?

Edit: I see your reasons in your other thread.

To answer those questions - once a week is plenty for me :-)

And I have trusted D4 for decades...

Edit2: (well okay - since 1992ish)

http://www.thinkman.com/dimension4/

Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

i exchanged the ie things with _inetgetsource, and funny thing: the hour is correct now.

this is not possible, maybe it was my fault somewhere.

j.

Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...