kctvt Posted June 11, 2022 Share Posted June 11, 2022 How to check Live Time (Time Online) ? Hi, I want to get live time (time online) , because of time in PC can change (so it's not ok). That's why I'm finding solution to get live time, maybe better. Link to comment Share on other sites More sharing options...
Musashi Posted June 11, 2022 Share Posted June 11, 2022 (edited) 3 hours ago, kctvt said: How to check Live Time (Time Online) ? Not sure if this is, what you are looking for : (Author is @guinness - Source from : https://www.autoitscript.com/wiki/Snippets_(_Internet_)#GetTimeOnline) ; Retrieve the current time from TimeAPI.org. Ideal if your Windows clock is out of sync. ConsoleWrite(_GetTimeOnline(0) & @CRLF) ; TimeZone UTC. ; #FUNCTION# ==================================================================================================================== ; Name ..........: _GetTimeOnline ; Description ...: Retrieve the current date and time from TimeAPI.org. ; Syntax ........: _GetTimeOnline($iTimeZone) ; Parameters ....: $iTimeZone - An integer value of the timezone . ; 0 - UTC (Universal Time) ; 1 - EST (Eastern Time) ; 2 - CST (Central Time) ; 3 - MST (Mountain Time) ; 4 - PST (Pacific Time) ; 5 - AKST (Alaska Time) ; 6 - HAST (Hawaii-Aleutian Time) ; Return values .: Success: Returns the current Date and Time in the format YYYY/MM/DD HH:MM:SS ; Failure: Sets @error to non-zero and returns the same format as a successful return but using the system time. ; Author ........: guinness ; Link ..........: According to http://www.programmableweb.com/api/timeapi, this is for non-commercial use. ; Example .......: Yes ; =============================================================================================================================== Func _GetTimeOnline($iTimeZone) Local $aTimeZone[7] = ['utc', 'est', 'cst', 'mst', 'pst', 'akst', 'hast'] Local $sRead = BinaryToString(InetRead('http://www.timeapi.org/' & $aTimeZone[$iTimeZone] & '/now?format=\Y/\m/\d%20\H:\M:\S')) If @error Then Return SetError(1, 0, @YEAR & '/' & @MON & '/' & @MDAY & ' ' & @HOUR & ':' & @MIN & ':' & @SEC) EndIf Return $sRead EndFunc ;==>_GetTimeOnline Edited June 11, 2022 by Musashi kctvt 1 "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
kctvt Posted June 11, 2022 Author Share Posted June 11, 2022 8 hours ago, Musashi said: Not sure if this is, what you are looking for : (Author is @guinness - Source from : https://www.autoitscript.com/wiki/Snippets_(_Internet_)#GetTimeOnline) ; Retrieve the current time from TimeAPI.org. Ideal if your Windows clock is out of sync. ConsoleWrite(_GetTimeOnline(0) & @CRLF) ; TimeZone UTC. ; #FUNCTION# ==================================================================================================================== ; Name ..........: _GetTimeOnline ; Description ...: Retrieve the current date and time from TimeAPI.org. ; Syntax ........: _GetTimeOnline($iTimeZone) ; Parameters ....: $iTimeZone - An integer value of the timezone . ; 0 - UTC (Universal Time) ; 1 - EST (Eastern Time) ; 2 - CST (Central Time) ; 3 - MST (Mountain Time) ; 4 - PST (Pacific Time) ; 5 - AKST (Alaska Time) ; 6 - HAST (Hawaii-Aleutian Time) ; Return values .: Success: Returns the current Date and Time in the format YYYY/MM/DD HH:MM:SS ; Failure: Sets @error to non-zero and returns the same format as a successful return but using the system time. ; Author ........: guinness ; Link ..........: According to http://www.programmableweb.com/api/timeapi, this is for non-commercial use. ; Example .......: Yes ; =============================================================================================================================== Func _GetTimeOnline($iTimeZone) Local $aTimeZone[7] = ['utc', 'est', 'cst', 'mst', 'pst', 'akst', 'hast'] Local $sRead = BinaryToString(InetRead('http://www.timeapi.org/' & $aTimeZone[$iTimeZone] & '/now?format=\Y/\m/\d%20\H:\M:\S')) If @error Then Return SetError(1, 0, @YEAR & '/' & @MON & '/' & @MDAY & ' ' & @HOUR & ':' & @MIN & ':' & @SEC) EndIf Return $sRead EndFunc ;==>_GetTimeOnline Yes. Thank you bro. But this source dont work. I try : ConsoleWrite(_GetTimeOnline(0) & @CRLF) ; ConsoleWrite(_GetTimeOnline(1) & @CRLF) ; ConsoleWrite(_GetTimeOnline(2) & @CRLF) ; ConsoleWrite(_GetTimeOnline(3) & @CRLF) ; ..... etc .... Result always : 2022/06/11 23:29:25 And PC Time also is : 2022/06/11 23:29:25 Do you have another solution ? Link to comment Share on other sites More sharing options...
water Posted June 11, 2022 Share Posted June 11, 2022 What do you expect to be the correct result? Please post an example with current time returned by _GetTimeOnline and the expected result. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
Musashi Posted June 11, 2022 Share Posted June 11, 2022 Just now, kctvt said: Result always : 2022/06/11 23:29:25 . Do you have another solution ? Sorry, I just googled for timeapi.org and the site is apparently Down. In this case the function sets the @error macro and returns the system time of the computer. I'll see if there are other sources. "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
kctvt Posted June 11, 2022 Author Share Posted June 11, 2022 8 minutes ago, water said: What do you expect to be the correct result? Please post an example with current time returned by _GetTimeOnline and the expected result. I want to get GMT Time after use _GetTimeOnline Link to comment Share on other sites More sharing options...
kctvt Posted June 11, 2022 Author Share Posted June 11, 2022 7 minutes ago, Musashi said: Sorry, I just googled for timeapi.org and the site is apparently Down. In this case the function sets the @error macro and returns the system time of the computer. I'll see if there are other sources. Humm, ok bro. timeapi.org was down. I found https://timeapi.io/ , but dont know how to use =.= Link to comment Share on other sites More sharing options...
water Posted June 11, 2022 Share Posted June 11, 2022 The forum provides a few examples how to use NTP (network time protocol) like: My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
kctvt Posted June 11, 2022 Author Share Posted June 11, 2022 15 minutes ago, Musashi said: Sorry, I just googled for timeapi.org and the site is apparently Down. In this case the function sets the @error macro and returns the system time of the computer. I'll see if there are other sources. I found more : http://worldclockapi.com/ http://worldclockapi.com/api/json/est/now Link to comment Share on other sites More sharing options...
kctvt Posted June 11, 2022 Author Share Posted June 11, 2022 3 minutes ago, water said: The forum provides a few examples how to use NTP (network time protocol) like: I'll read this, thank you bro Link to comment Share on other sites More sharing options...
Musashi Posted June 11, 2022 Share Posted June 11, 2022 (edited) @kctvt : Perhaps the following is already sufficient for your purposes : Most websites (Google, for example) have a date/time header in their responses. You can just ping them to get the current time. Global $iError = 0, $oErrorChk = ObjEvent("AutoIt.Error", "ObjErrChk") Global $sDateTime = GetDateTimeFromNet() If @error Then MsgBox(BitOR(4096, 16), "Message : ", "An error has occurred : " & @error & @CRLF) Else MsgBox(BitOR(4096, 64), "Date / Time : ", $sDateTime & @CRLF) EndIf Func GetDateTimeFromNet($bProxy = False, $sProxy = "", $sURL = "http://www.google.com/") Local $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") If $iError Then Return SetError(1, 0, 0) If $bProxy Then $oHttp.SetProxy(2, $sProxy) $oHTTP.Open("GET", $sURL, False) $oHTTP.Send() If $iError Then Return SetError(2, 0, 0) Local $sDT = $oHTTP.GetResponseHeader("Date") $oHTTP = Null Return($sDT) EndFunc Func ObjErrChk() $iError += 1 MsgBox(BitOR(4096, 16), "COM-Error : ", _ $oErrorChk.scriptline & @CRLF & _ $oErrorChk.windescription & @CRLF & _ $oErrorChk.number & " | " & Hex($oErrorChk.number) & @CRLF) EndFunc Edited June 11, 2022 by Musashi typo "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
Musashi Posted June 11, 2022 Share Posted June 11, 2022 .cmom changed to .com. I still had that in the code for testing purposes to produce a COM error . "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
Musashi Posted June 11, 2022 Share Posted June 11, 2022 @kctvt : You may also check this one from @Nine : https://www.autoitscript.com/forum/topic/203759-is-there-a-way-to-get-time-online-because-the-times-on-the-computer-are-subject-to-change/?do=findComment&comment=1463129 #include <Constants.au3> #include <Date.au3> ;Local $String = BinaryToString(InetRead ("http://worldtimeapi.org/api/timezone/America/Toronto.txt",1)) Local $String = BinaryToString(InetRead ( "http://worldtimeapi.org/api/timezone/Europe/Amsterdam.txt",1)) ;MsgBox (0,"",$String) Local $Time = StringRegExp ($String,'datetime: (.+?)T(\d+:\d+:\d+)', $STR_REGEXPARRAYMATCH) MsgBox ($MB_SYSTEMMODAL,"",$Time[0] & " " & $Time[1]) hudsonhock and nitekram 1 1 "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
kctvt Posted June 13, 2022 Author Share Posted June 13, 2022 On 6/12/2022 at 1:34 AM, Musashi said: @kctvt : You may also check this one from @Nine : https://www.autoitscript.com/forum/topic/203759-is-there-a-way-to-get-time-online-because-the-times-on-the-computer-are-subject-to-change/?do=findComment&comment=1463129 #include <Constants.au3> #include <Date.au3> ;Local $String = BinaryToString(InetRead ("http://worldtimeapi.org/api/timezone/America/Toronto.txt",1)) Local $String = BinaryToString(InetRead ( "http://worldtimeapi.org/api/timezone/Europe/Amsterdam.txt",1)) ;MsgBox (0,"",$String) Local $Time = StringRegExp ($String,'datetime: (.+?)T(\d+:\d+:\d+)', $STR_REGEXPARRAYMATCH) MsgBox ($MB_SYSTEMMODAL,"",$Time[0] & " " & $Time[1]) Thank you Musashi, http://worldtimeapi.org/api is better, run very fast. 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