Sample code for 30+ languages & platforms
Lazarus Pascal

DateTime - Get as Unix Time String

Demonstrates the GetAsUnixTimeStr method.

Note: This example is only valid in Chilkat v9.5.0.65 or later.

Chilkat Lazarus Pascal Downloads

Lazarus Pascal
program ChilkatDemo;

// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.

{$IFDEF FPC}
  {$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}

uses
  {$IFDEF UNIX}
  cthreads,
  {$ENDIF}
  SysUtils,
  CkDllLoader,
  Chilkat.CkDateTime;

// ---------------------------------------------------------------------------

procedure RunDemo;
var
  dateTime: TCkDateTime;
  bLocal: Boolean;

begin
  dateTime := TCkDateTime.Create;

  dateTime.SetFromCurrentSystemTime();

  //  (in seconds since the epoch: 00:00:00 UTC on 1 January 1970)
  bLocal := True;
  WriteLn('Unix time: ' + dateTime.GetAsUnixTimeStr(bLocal));

  //  Sample output for test run on 2-Dec-2016: 

  //      Unix time: 1480661608


  dateTime.Free;

end;

// ---------------------------------------------------------------------------

begin

  try
    RunDemo;
  except
    on E: Exception do
      WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
  end;

  WriteLn;
  {$IFDEF MSWINDOWS}
  WriteLn('Press Enter to exit...');
  ReadLn;
  {$ENDIF}
end.