ZestSync

How do I get the current time in a different TimeZone in Delphi?

How do i get current time from different time zones in Delphi. If i use TidSNTP it will only give me the time zone in my locale.

1 Answer

You can easily convert local time to different time zone with delphi-tzdb (Time Zone Database for Delphi).

Following is example from its documentation.

var LSydney: TTimeZone; LMadeUpLocalTime, LUniversalTime, LSydneyTime: TDateTime; begin // Get the Sydney time zone LSydney := TBundledTimeZone.GetTimeZone('Australia/Sydney'); // Encode a local date/time value -- 14th March 2009 at 12:45:00 PM LMadeUpLocalTime := EncodeDateTime(2009, 03, 14, 12, 45, 00, 00); // Find out what was the time in Sydney at that moment LUniversalTime := TTimeZone.Local.ToUniversalTime(LMadeUpLocalTime); LSydneyTime := LSydney.ToLocalTime(LUniversalTime); WriteLn(Format('When in my time zone the time was %s, in Sydney it was %s.', [DateTimeToStr(LMadeUpLocalTime), DateTimeToStr(LSydneyTime)])); end; 
1

ncG1vNJzZmirpJawrLvVnqmfpJ%2Bse6S7zGiorp2jqbawutJoaGpqaGWFdoSOoaawZZSkeqp5xp6rZqyYmnqkwdGrnKesXam2rrGMoqVmmV2ZtqeyxKucp6xdqbausdmopZ5lmaN6pbHLqZ%2Bi

Lorie Orum

Update: 2024-05-18