Jump to content

Set time using a timeserver


piccaso
 Share

Recommended Posts

So i can query a timeserver using DAYTIME protocol

Local $recv, $sock, $cnt
if not TCPStartup() Then
    ConsoleWrite("TCPStartup() Error" &@cr)
    Exit
EndIf
$sock = TCPConnect(TCPNameToIP("ts1.univie.ac.at"), 13)
if $sock = -1 Then
    ConsoleWrite("TCPConnect() Error" &@cr)
    Exit
EndIf
While Not StringInStr($recv, @CR)
    $recv &= TCPRecv($sock, 64)
    $cnt += 1
    if $cnt > 2 Then
        Sleep (250)
    EndIf
    if $cnt > 15 Then
        ConsoleWrite("Connection Timeout" & @cr)
        ExitLoop
    EndIf
WEnd
ConsoleWrite($recv)
TCPCloseSocket($sock)
TCPShutdown()

the answer looks like 'Sat Oct 22 04:05:34 2005'

any sugestions about how to pass it to the os?

thanx in advance...

CoProc Multi Process Helper libraryTrashBin.nfshost.com store your AutoIt related files here!AutoIt User Map
Link to comment
Share on other sites

RunWait(@ComSpec & " /c DATE " &$DateTimeDetails, "", @SW_HIDE) should help (you are passing parameters to the inbuilt DOS DATE function - do a similar thing for the TIME function). Try executing from the command line to see what format/order your particular locale needs the date/time in.

Good luck!

NB: Check out w32tm.exe with the /resync /nowait options to use the preconfigured time servers in Windows. See http://www.microsoft.com/technet/prodtechn...95d482db3a.mspx

Edited by Confuzzled
Link to comment
Share on other sites

Check out the _DateTimeFormat function in Date.au3 - one of the standard UDFs bundled with AutoIT3.

;===============================================================================
;
; Description: Returns the date in the PC's regional settings format.
; Parameter(s): $date - format "YYYY/MM/DD"
; $sType - :
; 0 - Display a date and/or time. If there is a date part, display it as a short date.
; If there is a time part, display it as a long time. If present, both parts are displayed.
; 1 - Display a date using the long date format specified in your computer's regional settings.
; 2 - Display a date using the short date format specified in your computer's regional settings.
; 3 - Display a time using the time format specified in your computer's regional settings.
; 4 - Display a time using the 24-hour format (hh:mm).
; Requirement(s): None
; Return Value(s): On Success - Returns date in proper format
; On Failure - 0 and Set
; @ERROR to: 1 - Invalid $sDate
; 2 - Invalid $sType
; Author(s): Jos van der Zande

; Note(s): None...
;
;===============================================================================

Edited by Jos
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...