Check for daylight saving time with WMI on Vista/Win7

ぐ巨炮叔叔 提交于 2019-12-24 08:47:14

问题


How do I find out if the computer I'm on has daylight saving time in effect? (preferably using WMI)

According to this article at TechNet, I could query SELECT DaylightInEffect FROM Win32_ComputerSystem, but the property DaylightInEffect is not supported on Vista or Win7. As my program will run on various systems (XP, Vista, 7), I would appreciate some portable way of finding out.


回答1:


The documented supported OS list is not accurate, this works fine on Win7 when I try it. I can't think of any reason it wouldn't be supported on any other OS, it is easy to find out with the Win32 API (GetTimeZoneInformation).

You can use WmiCodeCreator for a quick check.




回答2:


Here is a boolean function that is implemented using the WMI query referenced in the question.

(Related: How Can I Determine My Time Zone Offset Using VBScript?)

Function IsDaylightInEffect()
    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
        IsDaylightInEffect = oItem.DaylightInEffect
        Exit For
    Next
End Function


来源:https://stackoverflow.com/questions/1797758/check-for-daylight-saving-time-with-wmi-on-vista-win7

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!