Function Reference


_Date_Time_SetLocalTime

Sets the current local date and time

#include <Date.au3>
_Date_Time_SetLocalTime ( $tSYSTEMTIME )

Parameters

$tSYSTEMTIME a $tagSYSTEMTIME structure that contains the new local date and time or a pointer to it

Return Value

Success: True
Failure: False

Remarks

The _Date_Time_SetLocalTime() function enables the SE_SYSTEMTIME_NAME privilege before changing the local time.

Related

$tagSYSTEMTIME, _Date_Time_GetLocalTime

Example

#include <Date.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIError.au3>
#include <WindowsConstants.au3>

; Under Vista and over the Windows API "SetLocalTime" may be rejected due to system security

Global $g_idMemo

Example()

Func Example()
        ; Create GUI
        GUICreate("Date_Time Get/Set LocalTime (v" & @AutoItVersion & ")", 400, 300)
        $g_idMemo = GUICtrlCreateEdit("", 2, 2, 396, 296, $WS_VSCROLL)
        GUICtrlSetFont($g_idMemo, 9, 400, 0, "Courier New")
        GUISetState(@SW_SHOW)

        ; Show current local time
        Local $tCur = _Date_Time_GetLocalTime()
        MemoWrite("Current date/time .: " & _Date_Time_SystemTimeToDateTimeStr($tCur))

        ; Set new local time
        Local $tNew = _Date_Time_EncodeSystemTime(8, 19, @YEAR, 3, 10, 45)
        If Not _Date_Time_SetLocalTime($tNew) Then
                MsgBox($MB_SYSTEMMODAL, "Error", "System clock cannot be SET" & @CRLF & @CRLF & _WinAPI_GetLastErrorMessage())
                Exit
        EndIf
        $tNew = _Date_Time_GetLocalTime()
        MemoWrite("New date/time .....: " & _Date_Time_SystemTimeToDateTimeStr($tNew))

        ; Reset local time
        _Date_Time_SetLocalTime($tCur)

        ; Show current local time
        $tCur = _Date_Time_GetLocalTime()
        MemoWrite("Current date/time .: " & _Date_Time_SystemTimeToDateTimeStr($tCur))

        ; Loop until the user exits.
        Do
        Until GUIGetMsg() = $GUI_EVENT_CLOSE
EndFunc   ;==>Example

; Write a line to the memo control
Func MemoWrite($sMessage)
        GUICtrlSetData($g_idMemo, $sMessage & @CRLF, 1)
EndFunc   ;==>MemoWrite