delphi

How to convert Chrome's cookie timestamp to a Delphi TDateTime?


I need to convert an integer from a Google Chrome cookie's timestamp to a Delphi TDateTime value.

For instance, this is one value extracted from an example cookie:

1765064691

The 'real' datetime of this value is 12/6/2025 8:44:51 PM, but I don't know how to get this same value in Delphi. Here is what I tried:

var d : TDateTime;
begin
  d := StrToDateTime(StrToInt('1765064691'));
end;

But I got an exception. Any ideas?


Solution

  • If that cookie comes from CEF then use the CefBaseTimeToDateTime function available in the uCEFMiscFunctions unit of the CEF4Delphi project to convert it.

    TCefBaseTime is an Int64 that represents a wall clock time in UTC.

    Values are not guaranteed to be monotonically non-decreasing and are subject to large amounts of skew. Time is stored internally as microseconds since the Windows epoch (1601).