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.
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With