How to format a Unix timestamp in Delphi?

前端 未结 3 1230
[愿得一人]
[愿得一人] 2021-02-04 07:36

I have

var timestamp: Longint;  
timestamp := Round((Now() - 25569.0 {Unix start date in Delphi terms} ) * 86400);

which I am using as a prima

3条回答
  •  悲哀的现实
    2021-02-04 07:46

    This is much faster

    // 4x faster than dateutils version
    function UNIXTimeToDateTimeFAST(UnixTime: LongWord): TDateTime;
    begin
    Result := (UnixTime / 86400) + 25569;
    end;
    
    // 10x faster than dateutils version
    function DateTimeToUNIXTimeFAST(DelphiTime : TDateTime): LongWord;
    begin
    Result := Round((DelphiTime - 25569) * 86400);
    end;
    

提交回复
热议问题