Delphi Firemonkey get UTC time

Viewed 609

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;
1 Answers

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)));
Related