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

CodeFunctionName
What is this?

Public

Tested

Original Work
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

Optional File2

Views 4,655

Downloads 1,372

CodeID
DB ID

ANmarAmdeen
602
Revisions

v1.0

Friday
June
22
2018