本地时间转UTC时间
dim SWDT, datetime, utcTime
Set SWDT = CreateObject("WbemScripting.SWbemDateTime")
datetime = "2019-10-11 12:00:00"
'本地时间转UTC时间
SWDT.SetVarDate datetime, True
utcTime = SWDT.GetVarDate (False)
UTC时间转本地时间
dim SWDT, datetime, localTime
Set SWDT = CreateObject("WbemScripting.SWbemDateTime")
datetime = "2019-10-11 12:00:00"
'UTC时间转本地时间
SWDT.SetVarDate datetime, False
localTime = SWDT.GetVarDate(True)
示例:
新建文本文件,写入以下代码,改后缀名为vbs。
dim SWDT, datetime, utcTime, localTime
Set SWDT = CreateObject("WbemScripting.SWbemDateTime")
datetime = "2019/10/11 12:00:00"
'本地时间转UTC时间
SWDT.SetVarDate datetime, True
utcTime = SWDT.GetVarDate (False)
'UTC时间转本地时间
SWDT.SetVarDate datetime, False
localTime = SWDT.GetVarDate(True)
Wscript.Echo "输入时间:" & datetime & vbnewline & "UTC时间:"& utcTime & vbnewline & "本地时间:"& localTime & vbnewline
运行效果如下:
来源:oschina
链接:https://my.oschina.net/u/4332632/blog/3375052