WMI中的DateTime數(shù)據(jù)類型保存的時間格式是UTC,與VBS中的時間類型不同。
有兩種方法可以轉(zhuǎn)換,一種是自己寫個函數(shù)解析:
代碼如下:
Function WMIDateStringToDate(DateTime)
WMIDateStringToDate = _
CDate(Mid(DateTime, 5, 2) &_
"/" &_
Mid(DateTime, 7, 2) &_
"/" &_
Left(DateTime, 4) &_
" " &_
Mid (DateTime, 9, 2) &_
":" &_
Mid(DateTime, 11, 2) &_
":" &_
Mid(DateTime, 13, 2))
End Function
另一種是使用SWbemDateTime對象
代碼如下:
Function WMIDateStringToDate(DateTime)
Set WbemDateTime = _
CreateObject("WbemScripting.SWbemDateTime")
WbemDateTime.Value = DateTime
WMIDateStringToDate = WbemDateTime.GetVarDate()
End Function