dakuyong
dakuyong

Reputation: 43

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?

Upvotes: 4

Views: 2232

Answers (1)

RRUZ
RRUZ

Reputation: 136391

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.

Upvotes: 14

Related Questions