如何使用 VBScript 确定我的时区偏移量?
Windows操作系统提供了TZ
环境变量。对于东部标准时间(纽约),它的值为EST5EDT
。但是,我正在寻找与UTC的符号整数偏移量。(东部标准时间为-5。)
如何使用 VBScript 确定我的时区偏移量?
Windows操作系统提供了TZ
环境变量。对于东部标准时间(纽约),它的值为EST5EDT
。但是,我正在寻找与UTC的符号整数偏移量。(东部标准时间为-5。)
这里是一个经过修订的函数,似乎考虑了夏令时的影响。 (灵感来自这个 Stack Overflow 问题。)
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
[未考虑夏令时的原始函数。]
以下是我对我的问题的回答 (原始来源)。
对于东部标准时间(纽约),此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