VBScript中的UTC时间分配

Chr*_*ris 10 vbscript utc date-format

有没有人在VBScript中有一个简单的方法来获取UTC的当前时间?

谢克斯,克里斯

Nie*_*ree 14

我用一种简单的技术

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

有关SWbemDateTime的更多信息

如果您想将UTC转换回本地时间,请执行以下操作:

Set dateTime = CreateObject("WbemScripting.SWbemDateTime")
        dateTime.SetVarDate now(),false  REM Where now is the UTC date
        wscript.echo cdate(dateTime.GetVarDate (true))
Run Code Online (Sandbox Code Playgroud)


Dis*_*ing 2

那里有很多例子。如果您可以访问注册表,则此操作将适合您:

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)
Run Code Online (Sandbox Code Playgroud)

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