怎样在VBS中利用Windows Management Instrumentation(WMI)获得系统时间和系统时区?

介绍:
下表介绍了如何在WinCC运行时使用“Windows Management Instrumentation(WMI)”来访问系统时间(计算机本地时间或世界调整时间)n

关于”Windows Management Instrumentation (WMI)“的详细信息请参见微软的文档
WinCC_SystemTimeVBS.zip ( 669 bytes )

No. Option
1

读取计算机本地时间
下面的脚本用于读取计算机本地时间n

支持的操作系统

Windows Server 2003
Windows XP
Windows 2000

代码

怎样在VBS中利用Windows Management Instrumentation(WMI)获得系统时间和系统时区?
图. 01

2

读取UTC(世界调整时间)
下面的脚本读取UTC(世界调整时间)n

支持的操作系统

Windows Server 2003
Windows XP
Windows 2000

代码

怎样在VBS中利用Windows Management Instrumentation(WMI)获得系统时间和系统时区?
图. 02

3定义本地与格林尼治时区的偏差
下面的脚本定义了本地时区与格林尼治时区的时差(以分钟为单位)
n

注意:
夏令时/冬令时的时间偏差没有计算进去。n

支持的操作系统

Windows Server 2003
Windows XP
Windows 2000

代码

怎样在VBS中利用Windows Management Instrumentation(WMI)获得系统时间和系统时区?
图. 03

4定义当前系统时区
下面的脚本定义了当前系统时区,提供了本地时区与格林尼治时区的时差(以分钟为单位)

注意:
夏令时/冬令时的时间偏差没有计算进去。

支持的操作系统

Windows Server 2003
Windows XP
Windows 2000

代码

怎样在VBS中利用Windows Management Instrumentation(WMI)获得系统时间和系统时区?
图. 04

5

获得当前时制“夏令时或者冬令时”
下面的脚本运行结果,“TRUE”表明当前是夏令时,否则为冬令时

支持的操作系统

Windows Server 2003
Windows XP
Windows 2000

代码

怎样在VBS中利用Windows Management Instrumentation(WMI)获得系统时间和系统时区?
图. 05

注意:
脚本中使用了”HMIRuntime.Trace”的方式,你可以使用全局脚本诊断窗口或者APDIAG输出窗口来查看结果。下面两个图片显示了脚本运行结果和当前系统时间设置。

怎样在VBS中利用Windows Management Instrumentation(WMI)获得系统时间和系统时区?
图. 06

怎样在VBS中利用Windows Management Instrumentation(WMI)获得系统时间和系统时区?
图. 07

原创文章,作者:ximenziask,如若转载,请注明出处:https://www.zhaoplc.com/plc338041.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2020年11月5日
下一篇 2021年4月12日

相关推荐

发表回复

登录后才能评论