Sample code for 30+ languages & platforms
Pascal (Lazarus/Delphi)

Extract Timestamp from ULID

See more ULID/UUID Examples

Extract the date/time from a ULID.

Important: Chilkat's ULID functionality was introduced in v9.5.0.94.

Chilkat Pascal (Lazarus/Delphi) Downloads

Pascal (Lazarus/Delphi)
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
  success: Boolean;
  ulid: string;
  dt: TCkDateTime;
  bLocal: Boolean;

begin
  success := False;

  ulid := '01GRH14AA82EY9A7S99YYF2QDY';

  dt := TCkDateTime.Create;

  //  Unix timestamps stored in ULIDs should be UTC...
  bLocal := False;
  //  Set the CkDateTime from the timestamp contained in the ULID
  success := dt.SetFromUlid(bLocal,ulid);
  if (success = False) then
    begin
      WriteLn('ULID was not valid.');
      Exit;
    end;

  //  You can now get the date/time in any desired format.
  //  For example:
  WriteLn('Unix timestamp = ' + dt.GetAsUnixTime(bLocal));
  WriteLn('RFC822 = ' + dt.GetAsRfc822(bLocal));
  WriteLn('Timestamp = ' + dt.GetAsTimestamp(bLocal));

  //  Sample output:

  //  Unix timestamp = 1675608861
  //  RFC822 = Sun, 05 Feb 2023 14:54:21 GMT
  //  Timestamp = 2023-02-05T14:54:21Z


  dt.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.