當我們使用EncodeTime函數EncodeTime(wHour,wMinute,wSecond,wMilliseconds)時,它不會將millisec值分配給結果。在Delphi 2010中編碼時間問題
我們使用以下編碼日期和時間
Result := EncodeDate(wYear, wMonth, wDay) +
EncodeTime(wHour, wMinute, wSecond, wMilliseconds);
,我們要分析爲DateTime具有價值Apr 10 2008 7:21:31:460PM
繩子,但編碼後,我們得到的輸出爲10/04/2008 07:21:31
。
結果只包含HH:MM:SS
值,而不包含millisec值。
請讓我們知道,無論如何格式化值並將其與millisec一起存儲在變量中。 * ** * ** * ** * ** * ** * ***功能,我試圖* ** * ** * ** * ***
function DateTimeParser(theString :string):TDateTime;
var wYear,wMonth,wDay,wHour, wMinute, wSecond,wMilliseconds : Word ;
Date,Month,Med :String;
Time : TDateTime;
testtime,testtime1 : TSystemTime;
var myDateTime : TDateTime;
begin
Month := Copy(theString,1,3) ;
if Month ='Jan' then wMonth := 01
else if Month ='Feb' then wMonth := 02
else if Month ='Mar' then wMonth := 03
else if Month ='Apr' then wMonth := 04
else if Month ='May' then wMonth := 05
else if Month ='Jun' then wMonth := 06
else if Month ='Jul' then wMonth := 07
else if Month ='Aug' then wMonth := 08
else if Month ='Sep' then wMonth := 09
else if Month ='Oct' then wMonth := 10
else if Month ='Nov' then wMonth := 11
else if Month ='Dec' then wMonth := 12
else ShowMessage('Not a Valid Month');
wYear := StrToInt(Copy(theString,8,4)) ;
wDay := StrToInt(Copy(theString,5,2)) ;
wHour := StrToInt(Copy(theString,13,2)) ;
wMinute := StrToInt(Copy(theString,16,2)) ;
wSecond := StrToInt(Copy(theString,19,2)) ;
wMilliseconds := StrToInt(Copy(theString,22,3)) ;
ShowMessage(IntToStr(wMilliseconds));
{if Copy(theString,25,2)= 'PM' then
wHour := wHour+12;}
Result := DateUtils.EncodeDateTime(wYear, wMonth, wDay,wHour, wMinute, wSecond, wMilliseconds);
//Result := Result+DateUtils.EncodeTime(wHour, wMinute, wSecond, wMilliseconds div 100);
myDateTime:= EncodeDate(2009,11,28)+EncodeTime(14,23,12,001);
ShowMessage(DatetimetoStr(myDateTime));
testtime1 := testtime;
Time :=EncodeTime(wHour, wMinute, wSecond, wMilliseconds);
ShowMessage(DateTimeToStr(Result));
**********************************************************************
end;
任何想法?
看到這個答案:http://stackoverflow.com/questions/1760929/how-to-encode-a-datetime-in-delphi/1760943#1760943 – Adrian 2011-02-28 14:42:53
謝謝阿德里安,我沒有嘗試使用該選項,但仍millisec價值沒有得到存儲。 – SSE 2011-02-28 14:51:18
「DateTimeParser」的結果確實包含毫秒。但是你的測試字符串'Apr 10 2008 7:21:31:460PM'不起作用。您需要用0'Apr 10 2008 07:21:31:460PM'填充小時。 – 2011-03-01 10:23:04