2

EncodeTime 関数 EncodeTime(wHour, wMinute, wSecond, wMilliseconds) を使用すると、結果にミリ秒値が割り当てられません。

以下を使用して、日付と時刻をエンコードしています

Result := EncodeDate(wYear, wMonth, wDay) +
  EncodeTime(wHour, wMinute, wSecond, wMilliseconds);

DateTime に解析したい文字列には値Apr 10 2008 7:21:31:460PMがありますが、エンコード後に出力を として取得します10/04/2008 07:21:31

Result には値のみが含まれHH:MM:SS、ミリ秒値は含まれません。

とにかく値をフォーマットし、ミリ秒とともに変数に保存する方法があるかどうかお知らせください。 * ** * ** * ** * ** * ** * ***試している機能* ** * ** * ** * ***

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;

何か案は?

4

3 に答える 3

2

わかりにくいかもしれませんが、デフォルトの日付と時刻の形式では、通常、秒とミリ秒はドット ( .) で区切られています。質問で示した文字列の例には、その位置にApr 10 2008 7:21:31:460PMコロン ( ) があります。:これにより、ミリ秒が削除される可能性があります。

于 2011-02-28T18:37:42.167 に答える
2

この形式を使用します HH:MM:SS.ZZZ

乾杯

于 2011-02-28T18:12:37.297 に答える