10

我如何从德尔福的不同时区获取当前时间。如果我使用 TidSNTP,它只会给我当地的时区。

4

1 回答 1

16

您可以使用delphi-tzdb (Delphi 的时区数据库)轻松地将本地时间转换为不同的时区。

以下是其文档中的示例。

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;
于 2012-07-01T09:41:29.683 回答