您的位置:首页 > 其它

时间TDateTime相当于是Double,即双精度数64位,终于查到它用11位表示e,53位表示精度(整数小数一起),最前面一位表示正负

2015-11-26 01:56 513 查看
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;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: