UTC time assignment in VBScript

Does anyone have simple tools in VBScript to get the current time in UTC?

Thanx, Chris

+8
utc vbscript date-format
source share
4 answers

I am using a simple method

Set dateTime = CreateObject("WbemScripting.SWbemDateTime") dateTime.SetVarDate (now()) wscript.echo "Local Time: " & dateTime wscript.echo "UTC Time: " & dateTime.GetVarDate (false) 

Additional Information About SWbemDateTime

If you want to convert UTC back to local time, follow these steps:

 Set dateTime = CreateObject("WbemScripting.SWbemDateTime") dateTime.SetVarDate now(),false REM Where now is the UTC date wscript.echo cdate(dateTime.GetVarDate (true)) 
+12
source share

There are many examples. If you can access the registry, this will work for you:

 od = now() set oShell = CreateObject("WScript.Shell") atb = "HKEY_LOCAL_MACHINE\System\CurrentControlSet\" &_ "Control\TimeZoneInformation\ActiveTimeBias" offsetMin = oShell.RegRead(atb) nd = dateadd("n", offsetMin, od) Response.Write("Current = " & od & "<br>UTC = " & nd) 

From http://classicasp.aspfaq.com/date-time-routines-manipulation/how-do-i-convert-local-time-to-utc-gmt-time.html

+2
source share

You can get the time offset from the Win32_TimeZone WMI class .

 myDate = "9/4/2013 17:23:08" For Each objItem In GetObject(_ "winmgmts:\\.\root\cimv2").ExecQuery(_ "Select * from Win32_TimeZone") bias = objItem.Bias Next myDate = DateAdd("n", bias, myDate) WScript.Echo myDate 
+1
source share

With SetVarDate, the offset change due to daylight saving time (from +060 to +120) happened too early. The RegRead method (HKLM \ .. \ ActiveTimeBias) has been enabled. If playback is required, simply set the PC clock just before and immediately after the expected transition time and check the results.

0
source share

All Articles