使用 VBScript 确定我的时区偏移量? [英] Determine my time zone offset using VBScript?
问题描述
如何使用 VBScript 确定我的时区偏移?
How can I determine my time zone offset using VBScript?
Windows 操作系统提供了 TZ
环境变量.对于东部标准时间(纽约),其值为 EST5EDT
.但是,我正在寻找 UTC 的有符号整数偏移量.(这是东部标准时间 -5.)
The Windows OS provides the TZ
environment variable. For Eastern Standard Time (New York), its value is EST5EDT
. However, I am looking for the signed integer offset from UTC. (This is -5 for Eastern Standard Time.)
推荐答案
这是一个经过修订的函数,它似乎考虑了夏令时.(灵感来自这个问题.)
Here is a revised function that appears to account for Daylight Saving Time. (Inspired by this SO question.)
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
<小时>
[不考虑夏令时的原始函数.]
这是我对我的问题的回答(原始来源).
Here is my answer to my question (original source).
对于东部标准时间(纽约),此 VBScript 函数将返回 -5:
For Eastern Standard Time (New York), this VBScript function will return -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
这篇关于使用 VBScript 确定我的时区偏移量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!