How to convert WMI DateTime to standard DateTime?

前端 未结 5 1121
栀梦
栀梦 2021-01-20 01:14

I\'m trying to read the install date from WMI (Win32_OperatingSystem.InstallDate). The return value looks like this: 20091020221246.000000+180. How can I get a

5条回答
  •  终归单人心
    2021-01-20 02:02

    Instead of parsing and extracting the values manually (how the accepted answer suggest), you can use the WbemScripting.SWbemDateTime object.

    check this sample

    function  WmiDateToTDatetime(vDate : OleVariant) : TDateTime;
    var
      FWbemDateObj  : OleVariant;
    begin;
      FWbemDateObj  := CreateOleObject('WbemScripting.SWbemDateTime');
      FWbemDateObj.Value:=vDate;
      Result:=FWbemDateObj.GetVarDate;
    end;
    

    For more info about this topic you can read this artile WMI Tasks using Delphi – Dates and Times

提交回复
热议问题