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;