如何在Delphi中使用DST将历史时间戳转换为不同的时区?
我需要在 Delphi (Win32) 中将历史时间戳从 GMT 转换为 BST。我无法使用操作系统中的当前区域设置进行转换,因为它没有历史时间的正确夏令时 (DST) 偏移量。
是否有我可以使用的 VCL API 或 Win32 API?
I need to convert a historical timestamp from GMT to BST in Delphi (Win32). I can't use the current regional settings in the OS to do the conversion because it won't have the correct daylight saving (DST) offset for the historical time.
Is there a VCL API or Win32 API I can use?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Delphi TZDB 可能有用。它的主要功能是有一个使用 tz 数据库 处理时间的类,如果它包含“足够历史”的数据,会让你使用 UTC 作为中介。 tz 数据库旨在为世界各地的所有时区以及闰年、夏令时、日历更改等的各种时移制定规则,因为它们自 Unix 纪元以来与 UTC 相关(1 月 1 日午夜, 1970)。
安装该软件包后,使用将遵循以下原则:
上述内容依赖于一些假设。首先,
GMT
和BST
是 tz 数据库中的有效别名。如果没有,那么您需要找到最近的城市。 (例如美国/纽约
)。第二个是我很确定我的代码是特定于 Delphi XE+ 的。 TZDB 声称可以在 Delphi 6 和更新版本(以及 FreePascal)上工作,因此对工作的调整应该很小。不幸的是,地区日期和时间非常复杂,尤其是如果追溯到 20 世纪之前。
Delphi TZDB may be of use. It's main feature is that has a class that handles times using the tz database, which, if it contains "historical enough" data, would let you use UTC as an intermediary. The tz database aims to have rules for all the time zones throughout the world and the various time shifts for things like leap years, daylight savings time, calendar changes, etc. as they relate to UTC since the Unix epoch (Midnight, Jan 1, 1970).
Once you have the package installed, usage would be along the lines of the following:
The above relies on a few assumptions. First of all, that
GMT
andBST
are valid aliases in the tz database. If not, then you'll need to find the closest cities. (e.g.America/New_York
). The second one is that I'm pretty sure my code is Delphi XE+ specific. TZDB claims to work on Delphi 6 and newer (and FreePascal) though, so the adjustments to work should be minor.Unfortunately regional dates and times are very complex, especially if you stretch back much before the 20th century.