Monday, July 20, 2015

Converting Local Time to UTC/GMT Time

A VBScript function to convert Local Time to UTC/GMT Time

Function Convert_to_GMT()
Dim var_offset
Dim WshShell
set WshShell = WScript.CreateObject("WScript.Shell")
var_offset, return value from ActiveTimeBias, is in minutes
var_offset = WshShell.RegRead("HKLM\System\CurrentControlSet\Control
\TimeZoneInformation\ActiveTimeBias")
Taking current date/time and adding to var_offset because UTC = local time + bias
Convert_to_GMT = DateAdd("n", var_offset, Now())
Msgbox (Convert_to_GMT)
End Function

Calling function
Convert_to_GMT()

Many people do get confuse between UTC and GMT. Actually UTC and GMT is one and the same thing [Link].
You can check whether this function is returning the correct value by visiting World Time Server.