Private Type SYSTEMTIME wYear As Integer wMonth As Integer wDayOfWeek As Integer wDay As Integer wHour As Integer wMinute As Integer wSecond As Integer wMilliseconds As Integer End Type
Private Declare Sub GetLocalTime Lib "kernel32" _ (lpSystemTime As SYSTEMTIME)
Private Declare Sub GetSystemTime Lib "kernel32" _ (ByRef lpSystemTime As SYSTEMTIME)
Private Declare Function SetSystemTime Lib "kernel32" _ (ByRef lpSystemTime As SYSTEMTIME) As Long
Private Sub Form_Load() Dim dTimeUTC As Date Dim dTimeLocal As Date
Dim uTime As SYSTEMTIME Dim lResult As Long
GetSystemTime uTime With uTime dTimeUTC = DateSerial(.wYear, .wMonth, .wDay) + _ TimeSerial(.wHour, .wMinute, .wSecond) End With
GetLocalTime uTime With uTime dTimeLocal = DateSerial(.wYear, .wMonth, .wDay) + _ TimeSerial(.wHour, .wMinute, .wSecond) End With
s = "Current UTC time : " & Format$(dTimeUTC, "yyyy-mm-dd hh:nn:ss") & vbCrLf s = s & "Current Local time : " & Format$(dTimeLocal, "yyyy-mm-dd hh:nn:ss")
MsgBox s
dTimeUTC = DateAdd("h", 1, dTimeUTC) With uTime .wYear = Year(dTimeUTC) .wMonth = Month(dTimeUTC) .wDay = Day(dTimeUTC) .wHour = Hour(dTimeUTC) .wMinute = Minute(dTimeUTC) .wSecond = Day(dTimeUTC) End With
lResult = SetSystemTime(uTime)
If lResult <> 0 Then MsgBox "Time advanced 1 hour:" & Format$(Now, "yyyy-mm-dd hh:nn:ss"), vbOKOnly, "Advanced" dTime = DateAdd("h", -1, Now) Time = dTime Date = dTime MsgBox "Time reset:" & Format$(Now, "yyyy-mm-dd hh:nn:ss"), vbOKOnly, "Reset" Else MsgBox "Set system time returned error " & _ CStr(lResult) & ":" & CStr(Err.LastDllError), vbOKOnly, "Set Failed" End If End Sub |