在 .net CF 3.5 中获取特定时区?
我想在我的 PocketPC 上安装一个世界时钟。 获取当地时间没有问题,获取UTC时间更不是问题。 但我似乎无法获得特定时区? 假设我想要纽约当前的时区,不知道它是否是夏令时(所以我不知道它是东部时间 (GMT-5) 还是东部夏令时 (GMT-4))。
遗憾的是,Compact Framework 中似乎不存在 TimeZoneInfo,所以我想知道除了手动硬编码未来 10 年所需时区的夏令时更改之外是否真的没有其他方法以获得正确的转换...
编辑:TimeZone 存在,但它是一个我必须自己实现的抽象类,我想避免它,因为它很容易出错,并且需要在 DST 周转日期上使用一些魔法。
I'd like to have a World Clock on my PocketPC. Getting the Local Time is no problem, and getting the UTC Time is even less a Problem. But I seem unable to get a specific Time Zone? Say I want the current Time Zone for New York, not knowing if it's Daylight Saving Time or not (so I do not know if it's Eastern Time (GMT-5) or Eastern Daylight (GMT-4)).
Sadly, TimeZoneInfo does not seem to exist in Compact Framework, so I wonder if there is really no other way than manually hardcoding the Daylight Saving Time changes for the desired time zones for the next 10 years in order to get a proper conversion...
Edit: TimeZone exists, but is an abstract Class that I'd have to implement myself, which I'd like to avoid because it's error prone and requires some magic on the DST Turnaround dates.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
OpenNetCF 库支持时区。
编辑:Compact Framework 支持 TimeZone,但正如迈克尔指出的那样,这是一个抽象类!
The OpenNetCF library supports TimeZones.
EDIT: Compact Framework supports TimeZone, but as Michael pointed out that's an abstract class!
时区怎么样Windows Mobile 上的 C#
How about TimeZones with C# on Windows Mobile
如何使用网络服务下载最新的时区信息?
http://www.twinsun.com/tz/tz-link.htm
How about using a web service to download up-to-date timezone information?
http://www.twinsun.com/tz/tz-link.htm
请查看 http://www.michaelbrumm.com/simpletimezone.html。 还有一种方法可以从注册表中获取时区信息(不仅仅是您的本地时区),请参阅 http://msdn.microsoft.com/en-us/library/ms725481(VS.85).aspx
更新:也许这可以帮助:http://social.msdn.microsoft。 com/forums/en-US/windowsgeneraldevelopmentissues/thread/feed3c46-18ea-4d5a-b5cf-7d85823fae01/
我不确定紧凑型设备是否具有相同的信息,但您可以从 PC 中提取时区然后将它们存储在紧凑设备上的结构或文件中。 但您可能需要偶尔更新一次,因为这些事情往往会发生变化。
Take a look at http://www.michaelbrumm.com/simpletimezone.html. There's also a way to fetch the time zones information from the registry (not just your local time zone), see http://msdn.microsoft.com/en-us/library/ms725481(VS.85).aspx
UPDATE: maybe this could help: http://social.msdn.microsoft.com/forums/en-US/windowsgeneraldevelopmentissues/thread/feed3c46-18ea-4d5a-b5cf-7d85823fae01/
I'm not sure if a compact device has the same information, but you could extract the time zones from a PC and then store them in a structure or a file on a compact device. But you would then probably have to update it once in a while, since these things tend to change.