使用VBScript确定我的时区偏移量?

Dav*_*dRR 5 vbscript wmi timezone utc timezone-offset

如何使用VBScript确定我的时区偏移量

Windows操作系统提供TZ环境变量.对于东部标准时间(纽约),其价值为EST5EDT.但是,我正在寻找UTC的有符号整数偏移量.(东部标准时间为-5.)

Dav*_*dRR 10

这是一个修改后的功能,似乎考虑了夏令时.(受到这个SO问题的启发.)

Function GetTimeZoneOffset()
    Const sComputer = "."

    Dim oWmiService : Set oWmiService = _
        GetObject("winmgmts:{impersonationLevel=impersonate}!\\" _
                  & sComputer & "\root\cimv2")

    Set cItems = oWmiService.ExecQuery("SELECT * FROM Win32_ComputerSystem")

    For Each oItem In cItems
        GetTimeZoneOffset = oItem.CurrentTimeZone / 60
        Exit For
    Next
End Function
Run Code Online (Sandbox Code Playgroud)

[不考虑夏令时的原始功能.]

这是我对我的问题的答案(原始来源).

对于东部标准时间(纽约),此VBScript函数将返回-5:

Function GetTimeZoneOffset()
    Const sComputer = "."

    Dim oWmiService : Set oWmiService = _
        GetObject("winmgmts:{impersonationLevel=impersonate}!\\" _
                  & sComputer & "\root\cimv2")

    Dim cTimeZone : Set cTimeZone = _
        oWmiService.ExecQuery("Select * from Win32_TimeZone")

    Dim oTimeZone
    For Each oTimeZone in cTimeZone
        GetTimeZoneOffset = oTimeZone.Bias / 60
        Exit For
    Next
End Function
Run Code Online (Sandbox Code Playgroud)