在 Windows XP/Server 2003 下将新旧本地时间转换为 UTC

发布于 2024-07-30 19:16:49 字数 2508 浏览 2 评论 0原文

我的应用程序将过去和现在的日期从本地时间转换为 UTC。

我需要确保遵守 Windows 未来的任何 DST 更新,同时仍然正确处理过去的日期。

该应用程序是用 C++ 编写的,在 Server 2003 上运行。

我研究过的选项:

那么...

  • ...还有其他人使用原始注册表解决方案来执行此操作吗?

  • ...还有其他建议吗?

(编辑:发现 dst_calc_engine 不不支持夏令时更新)

My application converts past and present dates from local time to UTC.

I need to ensure I will honor any future DST updates to Windows while still correctly handling past dates.

The application is written in C++ and is running on Server 2003.

Options I've researched:

So...

  • ... is anyone else using the raw registry solution to do this?

  • ... any other suggestions?

(edit: found out dst_calc_engine doesn't support DST updates)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

余厌 2024-08-06 19:16:49

我想我更愿意根据 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ 注册表中的信息重新实现 GetTimeZoneInformationForYear 和可能的 GetDynamicTimeZoneInformation时区

这样,您的代码将遵循 Windows 更新,并且您可以将脏代码替换为上层平台上的实际实现。

由于您不想使用外部数据库,因此我认为没有其他可行的选择。

I think I'd prefer to re-implement GetTimeZoneInformationForYear and possibly GetDynamicTimeZoneInformation based on the information in the registry at HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones.

That way, your code will follow Windows updates and you can swap the dirty code out for the actual implementation on up-level platforms.

Since you don't want to use an external database, I think no other options are viable.

清浅ˋ旧时光 2024-08-06 19:16:49

您可以将 gmtime() 和 localtime() 用于 2007 年及以后的日期(并利用
Windows DST 更新),并使用 Boost 或您提到的其他解决方案之一来使用 2006 年及更早版本的正确 DST 规则。

You could use gmtime() and localtime() for dates in 2007 and later (and take advantage
of Windows DST updates), and use Boost or one of the other solutions you mentioned to use the correct DST rules for 2006 and earlier.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文