在 Windows XP/Server 2003 下将新旧本地时间转换为 UTC
我的应用程序将过去和现在的日期从本地时间转换为 UTC。
我需要确保遵守 Windows 未来的任何 DST 更新,同时仍然正确处理过去的日期。
该应用程序是用 C++ 编写的,在 Server 2003 上运行。
我研究过的选项:
gmtime()
和localtime()
对于过去的日期并不总是正确的,因为它们只会遵守当前的 DST 规则。 (相关问题)< /p>- < p>tz 数据库 已退出,因为它需要单独的手动更新。
GetTimeZoneInformationForYear()
已退出,因为它需要 Vista/Server 2008。过去的 DST 信息存储在注册表中,但我正在寻找更高级别的信息。
Boost
date_time
:- 类
us_dst_rules
已弃用,并且不会随着操作系统更新而更新。 - 类
dst_calc_engine ;
是它的后继者,但它也不尊重操作系统更新。
- 类
那么...
...还有其他人使用原始注册表解决方案来执行此操作吗?
...还有其他建议吗?
(编辑:发现 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:
gmtime()
andlocaltime()
are not always correct for past dates because they will only ever observe current DST rules. (related SO question)A tz database is out because it requires a separate manual update.
GetTimeZoneInformationForYear()
is out because it requires Vista/Server 2008.Past DST information is stored in the registry, but I'm looking for something higher-level.
Boost
date_time
:- class
us_dst_rules
is deprecated and does not update if the OS updates. - class
dst_calc_engine<>
is its successor, but it does not respect OS updates either.
- class
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想我更愿意根据
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ 注册表中的信息重新实现
。GetTimeZoneInformationForYear
和可能的GetDynamicTimeZoneInformation
时区这样,您的代码将遵循 Windows 更新,并且您可以将脏代码替换为上层平台上的实际实现。
由于您不想使用外部数据库,因此我认为没有其他可行的选择。
I think I'd prefer to re-implement
GetTimeZoneInformationForYear
and possiblyGetDynamicTimeZoneInformation
based on the information in the registry atHKEY_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.
您可以将 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.