gpt4 book ai didi

delphi - 如何获取德尔福不同时区的当前时间?

转载 作者:行者123 更新时间:2023-12-03 14:41:19 29 4
gpt4 key购买 nike

如何获取德尔福不同时区的当前时间。如果我使用 TidSNTP,它只会提供我所在区域的时区。

最佳答案

您可以使用 delphi-tzdb (Time Zone Database for Delphi) 轻松将本地时间转换为不同时区.

以下是来自 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;

关于delphi - 如何获取德尔福不同时区的当前时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11280858/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com