0
我有一個問題,一個字符串轉換爲日期和時間。我知道我需要截斷字符串,但似乎無法找到任何有關如何操作的信息。我想其他人也會有這個問題,所以我想我會把它放在這裏用於研究目的。下面是代碼:德爾福日期時間轉換
uses
SysUtils,
ActiveX,
ComObj,
Variants;
procedure GetLogEvents;
const
wbemFlagForwardOnly = $00000020;
var
FSWbemLocator : OLEVariant;
FWMIService : OLEVariant;
FWbemObjectSet: OLEVariant;
FWbemObject : OLEVariant;
oEnum : IEnumvariant;
iValue : LongWord;
EventDate : TDateTime;
begin;
FSWbemLocator := CreateOleObject('WbemScripting.SWbemLocator');
FWMIService := FSWbemLocator.ConnectServer('localhost', 'root\CIMV2', '', '');
FWbemObjectSet:= FWMIService.ExecQuery(
'SELECT SourceName,TimeGenerated,ComputerName,EventCode,Message,RecordNumber ' +
' FROM Win32_NTLogEvent ' +
'WHERE Logfile="Application"','WQL',wbemFlagForwardOnly);
oEnum := IUnknown(FWbemObjectSet._NewEnum) as IEnumVariant;
while oEnum.Next(1, FWbemObject, iValue) = 0 do
begin
if not VarIsNull(FWbemObject.SourceName)
then Writeln(Format('SourceName %s',[String(FWbemObject.SourceName)]));
if not VarIsNull(FWbemObject.TimeGenerated)
then Writeln(StrToDateTime(FWbemObject.TimeGenerated));
而我得到的錯誤:
EConvertError: '20140307135950.000000-000' 不是一個有效的日期和時間。
誰能告訴我如何解決這個問題,好嗎?
啊,那優美的工作,謝謝! – user3393429