GetUTC

Get the time and date in Universal time based on local time
Uses w32tm / tz dos command in command prompt
Using temporary file that can be changed

Function GetUTC( Optional File2 = "C:\File1.txt")
 ' Gets the time in Universal time zone
 ' File2 = "C:\File1.txt"
 Shell "cmd /c w32tm /tz > " & File2
 DoEvents
 Application.Wait DateAdd("s", 1, Now)
 DoEvents
 ' wait for it to finish, then ...
 Dim iFile As Integer
 iFile = FreeFile()
 Open File2 For Input As #iFile
 Dim sData As String
 sData = Input(LOF(iFile), #iFile)
 Close #iFile
 DoEvents
 Kill File2
 TiOff = ""
 AN2 = " Bias: "
 AN1 = InStr(1, sData, AN2, vbTextCompare)
 AN3 = InStr(AN1, sData, " (") - AN1 - Len(AN2)
 If AN1 > 0 And AN3 > 0 Then
  TiOff = Mid(sData, AN1 + Len(AN2), AN3)
  TiOff = Left(TiOff, InStr(1, TiOff, "min") - 1)
 End If
 GetUTC = Date + TimeSerial(Hour(Now()), Minute(Now()) + Val(TiOff), Second(Now()))
End Function

Parameters

Optional File2

Views 121 Downloads 53

Perm link