時間TDateTime相當於是Double,即雙精度數64位,終於查到它用11位表示e,53位表示精度(整數小數一起),最前面一位表示正負


http://docwiki.embarcadero.com/RADStudio/Seattle/en/Internal_Data_Formats

關於Double的RTL函數,好像就一個:TryStrToFloat

function TryStrToFloat(const S: string; out Value: Double): Boolean; overload;
function TryStrToFloat(const S: string; out Value: Double; const FormatSettings: TFormatSettings): Boolean; overload;

好在還能按照指定格式轉換,運氣不錯。

--------------------------------------------------------------------------------------------------------------------------

順便復習一下absolute關鍵字的用法:

function DoubleToHex(const d: DOUBLE): string;
var
    Overlay: array[1..2] of LongInt absolute d;
begin
    try
        // "Little Endian" order
        RESULT := IntToHex(Overlay[2], 8) + IntToHex(Overlay[1], 8);
    except
    end;
end 

其中API函數FileTimeToSystemTime取來的時間,需要用Delphi提供的SystemTimeToDateTime函數做轉換,才能得到Delphi自定義的TDateTime數據(Delphi中的日期則是使用雙精度類型進行存儲的,整數部分表示距“1899-12-30”的天數,小數部分表示小時。如“2.75”這個數值則表示“1900-1-1 6:00PM”,“-1.25”則表示“1899-12-29 6:00 AM”)

function GetFileTimesUTC(const FileName: string): TDateTime;
var
    SystemTime: TSystemTime;
    FindData: WIN32_FIND_DATAW;
    FindHandle: THandle;
    fn: string;
begin
    Result := 0;
    FindHandle := INVALID_HANDLE_VALUE;

    FindHandle := FindFirstFileW(strCheminToUnicode(fn), FindData);
    if FindHandle <> INVALID_HANDLE_VALUE then
        if FileTimeToSystemTime(FindData.ftLastWriteTime, SystemTime) then
        begin
        Result := SystemTimeToDateTime(SystemTime);
        end;
    if FindHandle <> INVALID_HANDLE_VALUE then
        Windows.FindClose(FindHandle);
end;

比如這個數:

2014-07-07, 09:31:25 ,經過調試,在Delphi里的TDateTime值是:41827.355157 (小數點前是天數,小數點后是小時)。用例子驗證一下天數:

 

procedure TForm1.Button2Click(Sender: TObject);
var
    dd: integer;
    hh: Int64; 
    mydate : TDateTime;
    myreal : Double;
begin
    dd := 41827;
    mydate := EncodeDate(1899, 12, 30);
    mydate := mydate + dd;
    ShowMessage(FormatDateTime('yyyy-mm-dd', mydate));
end;

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM