将TimeOfLastReset的值转换为日期时间

时间:2017-10-24 06:19:20

标签: vb.net-2010 wmi-query valueconverter

我正在运行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

1 个答案:

答案 0 :(得分:1)

TimeOfLastReset属性为CIM_DATETIME format

  

您可以访问所有公共信息模型( CIM )的日期和时间   WMI使用两种固定长度格式之一WMI和。SWbemDateTime    CIM 。在脚本编写中,使用SWbemDateTime object将这些转换为常规日期和时间。

  

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 对象是一个解析和设置Common的辅助对象   信息模型( CIM )日期时间值。

==> cscript //NOLOGO D:\VB_scripts\SO\46903451.vbs

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

输出(截断):

dir = path/to/annotations