Jump to content

Get time from page


Go to solution Solved by Danp2,

Recommended Posts

  • Melba23 changed the title to Get time from page

#include <Date.au3>

_GetTimeFromNTP("http://vnexpress.net")

Func _GetTimeFromNTP($sNTPServer)
    Local $sData = ""
    TCPStartup()
    If TCPNameToIP($sNTPServer) = "" Then Return SetError(1)
    UDPStartup()
    $aSocket = UDPOpen(TCPNameToIP($sNTPServer), 123)
    $sStatus = UDPSend($aSocket, _MakePacket())
    While $sData = ""
        $sData = UDPRecv($aSocket, 100)
        Sleep(250)
    WEnd
    UDPCloseSocket($aSocket)
    TCPShutdown()
    $sValue = _UnsignedHexToDecimal(StringMid($sData, 83, 8))
    $aTimeZone = _Date_Time_GetTimeZoneInformation()
    $sUTC = _DateAdd("s", $sValue, "1900/01/01 00:00:00")
    If $aTimeZone[0] <> 2 Then
        $iTimeZoneOffset = ($aTimeZone[1]) * -1
    Else
        $iTimeZoneOffset = ($aTimeZone[1] + $aTimeZone[7]) * -1
    EndIf
    $sLocalTime = _DateAdd("n", $iTimeZoneOffset, $sUTC)
    ConsoleWrite($sLocalTime & @CRLF)
EndFunc

Func _MakePacket()
    Local $x, $sPacket = "1b0e01000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
    While $sPacket
        $x &= Chr(Dec(StringLeft($sPacket, 2)))
        $sPacket = StringTrimLeft($sPacket, 2)
    WEnd
    Return $x
EndFunc

Func _UnsignedHexToDecimal($sInput)
    $x = StringRight($sInput, 1)
    $sInput = StringTrimRight($sInput, 1)
    Return Dec($sInput) * 16 + Dec($x)
EndFunc

 

 

it can't be done  :(

i need to get the actual time UTC+7 .
Not time on my computer

Thanks 

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