Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UTC Time Assignment in VBScript

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

Thanx, Chris

like image 883
Chris Avatar asked Apr 08 '13 19:04

Chris


People also ask

How do you format UTC time?

The UTC Time Format For instance, UTC time in ISO-8601 is xx:xx:xxZ. The Z letter is added without a space. Another UTC format is a 12-hour clock time (AM/PM) xx:xx:xx.

What is UTC time stamp format?

Times are expressed in UTC (Coordinated Universal Time), with a special UTC designator ("Z"). Times are expressed in local time, together with a time zone offset in hours and minutes. A time zone offset of "+hh:mm" indicates that the date/time uses a local time zone which is "hh" hours and "mm" minutes ahead of UTC.

Is new date () UTC or local?

getTime() returns the number of milliseconds since 1970-01-01. If you create a new Date using this number, ex: new Date(Date. getTime()); it will be UTC, however when you display it (ex: through the chrome dev tools console) it will appear to be your local timezone.


3 Answers

I use a simple technique

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

More info on SWbemDateTime

If you wanted to convert UTC back to local time do this:

Set dateTime = CreateObject("WbemScripting.SWbemDateTime")
        dateTime.SetVarDate now(),false  REM Where now is the UTC date
        wscript.echo cdate(dateTime.GetVarDate (true))
like image 67
Niederee Avatar answered Nov 02 '22 00:11

Niederee


There are lots of examples out there. If you can access the registry this one 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

like image 23
Display Name is missing Avatar answered Nov 01 '22 23:11

Display Name is missing


You can get time bias from 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
like image 35
seeker Avatar answered Nov 02 '22 00:11

seeker