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 (小数点前是天数,小数点后是小时)