Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert C/unix integer datetime in seconds since 1970 to DateTime in Delphi?

I know how to use python's time to convert "1328834615" to a date.

>>> import time
>>> time.ctime(1328834615)
'Fri Feb 10 08:43:35 2012'

How do I do it using Delphi?

like image 923
dakuyong Avatar asked Dec 09 '22 02:12

dakuyong


1 Answers

Try using the UnixToDateTime function which is part of the DateUtils unit.

{$APPTYPE CONSOLE}

uses
  DateUtils,
  SysUtils;

Var
  Dt : TDateTime;
begin
  try
    Dt := UnixToDateTime(1328834615);
    //do something
    Writeln(FormatDateTime('ddd mmm d hh:nn:ss yyyy', Dt));

  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
  Readln;
end.
like image 130
RRUZ Avatar answered May 22 '23 08:05

RRUZ