将 TimeOfLastReset 的值转换为日期时间

convert value of TimeOfLastReset to date time

我正在 运行 wmi 查询以获取 TimeOfLastReset,我得到这样的值 20171024080309.437500+420 我如何将其转换为日期时间

这是我在 vb.net

中获取 TimeOfLastReset 的代码
strComputer = "." 
Set objWMIService = GetObject("winmgmts:\" & strComputer & "\root\CIMV2") 
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapter",,48) 
For Each objItem in colItems 
   Wscript.Echo "-----------------------------------"
   Wscript.Echo "Win32_NetworkAdapter instance"
   Wscript.Echo "-----------------------------------"
   Wscript.Echo "TimeOfLastReset: " & objItem.TimeOfLastReset
Next

TimeOfLastReset 属性 是 CIM_DATETIME format

You can access all Common Information Model (CIM) dates and times in WMI by using one of two fixed-length formats specific to WMI and CIM. In scripting, use the SWbemDateTime object to convert these to regular dates and times.


The SWbemDateTime object is a helper object to parse and set Common Information Model (CIM) datetime values.

strR = ""                           ' collect results to a string variable  
strComputer = "." 
Set objWMIService = GetObject("winmgmts:\" & strComputer & "\root\CIMV2") 
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapter",,48)

' Create a new datetime object.
Set objDateTime = CreateObject("WbemScripting.SWbemDateTime")
For Each objItem in colItems
   strR = strR & vbNewLine & "-----------------------------------"
   strR = strR & vbNewLine & "Win32_NetworkAdapter instance"
   strR = strR & vbNewLine ' & "-----------------------------------"

   ' The TimeOfLastReset property is a CIM_DATETIME
   strR = strR & "TimeOfLastReset: " & objItem.TimeOfLastReset
   objDateTime.Value = objItem.TimeOfLastReset

   ' Display the date using the VT_DATE format.
   strR = strR & " local=" & CStr( objDateTime.GetVarDate( True ))
   strR = strR & " UTC="   & CStr( objDateTime.GetVarDate( False))
Next
' the only "echo" allows to run the script using `wscript` or `cscript` host 
Wscript.Echo strR

输出(截断):

==> cscript //NOLOGO D:\VB_scripts\SO903451.vbs

-----------------------------------
Win32_NetworkAdapter instance
TimeOfLastReset: 20171024094043.491317+120 local=24/10/2017 09:40:43 UTC=24/10/2017 07:40:43
-----------------------------------
…