本文介绍了如何在Delphi中的其他TimeZone中获取当前时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

如何从Delphi中的不同时区获取当前时间.如果我使用TidSNTP,则只会在我的语言环境中提供时区.

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.

推荐答案

您可以使用 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;

这篇关于如何在Delphi中的其他TimeZone中获取当前时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 15:15