Search code examples
delphifiremonkeydelphi-10.3-rio

Delphi Firemonkey get UTC time


How does one get the UTC time in Firemonkey?

I tried this code from another Stackoverflow answer but it appears GetSystemTime() is not available in FMX.

function NowUTC: TDateTime;
Var UTC: TSystemTime;
begin
  GetSystemTime(UTC);
  Result := SystemTimeToDateTime(UTC);
end;

Solution

  • If you add DateUtils to the uses clause, you can use the TTimeZone class, its Local class property, and the ToUniversalTime method:

    ShowMessage(DateTimeToStr(TTimeZone.Local.ToUniversalTime(Now)));