由未经FindSystemTimeZoneById发现GetSystemTimeZones为什么返回某些时区? [英] Why are some time zones returned by GetSystemTimeZones not found by FindSystemTimeZoneById?
问题描述
我有一个奇怪的问题,我似乎无法化解。当我打电话 TimeZoneInfo.GetSystemTimeZones
在我的Win 7的64位机器,我得到101结果。当我打电话 TimeZoneInfo.FindSystemTimeZoneById
有关每个并传递的TimeZoneInfo对象的StandardName属性,其中3扔TimeZoneNotFoundException。
I've got an odd problem I can't seem to resolve. When I call TimeZoneInfo.GetSystemTimeZones
on my Win 7 x64 machine I get 101 results. When I call TimeZoneInfo.FindSystemTimeZoneById
on each of these and pass the StandardName attribute of the TimeZoneInfo object, 3 of them throw TimeZoneNotFoundException.
下面是一个示例:
var tzs = TimeZoneInfo.GetSystemTimeZones();
foreach (var timeZoneInfo in tzs.OrderBy(t => t.BaseUtcOffset))
{
try
{
TimeZoneInfo.FindSystemTimeZoneById(timeZoneInfo.StandardName);
}
catch (TimeZoneNotFoundException)
{
Console.WriteLine(timeZoneInfo.DisplayName + "|" + timeZoneInfo.StandardName + "|" + timeZoneInfo.BaseUtcOffset);
}
}
Console.ReadLine();
这已经很难找到协调世界时,耶路撒冷标准时间和马来半岛标准时间。以马来西亚等的情况下,我可以看到它的入口时,我看可用时区在我的区域设置,但它显示的显示名称属性,而不是StandardName:
This has trouble finding "Coordinated Universal Time", "Jerusalem Standard Time" and "Malay Peninsula Standard Time". Taking a case like Malaysia, I can see an entry for it when I look at the available time zones in my regional settings, although it's showing the DisplayName attribute rather than the StandardName:
不过,我可以浏览注册表HKEY_LOCAL_MACHINE \ SOFTWARE \微软\的Windows NT \ CURRENTVERSION \时区的时候看不出来任何名称在
However, I can't see it under either name when browsing the registry at HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones
这是怎么回事呢?为什么不能在马来西亚时区的名字被载入?
What's going on here? Why can't the Malaysia time zone be loaded by name?
请使用其他图书馆没有选择时区的实现 - 我只是想要得到这个问题的底部了。谢谢!
Please no alternative time zone implementations using other libraries - I just want to get to the bottom of this issue for now. Thanks!
推荐答案
<一个href="http://msdn.microsoft.com/en-us/library/system.timezoneinfo.findsystemtimezonebyid.aspx"><$c$c>TimeZoneInfo.FindSystemTimeZoneById$c$c>方法接受时区id作为参数。您正在使用 timeZoneInfo.StandardName
代替。
看来,是为<一个这3个区域价值href="http://msdn.microsoft.com/en-us/library/system.timezoneinfo.standardname.aspx"><$c$c>TimeZoneInfo.StandardName$c$c>和<一href="http://msdn.microsoft.com/en-us/library/system.timezoneinfo.id.aspx"><$c$c>TimeZoneInfo.Id$c$c>特性不同。使用这样的:
It seems, that for these 3 zones values for TimeZoneInfo.StandardName
and TimeZoneInfo.Id
properties are different. Using this:
TimeZoneInfo.FindSystemTimeZoneById(timeZoneInfo.Id);
将解决这个问题。
will solve the issue.
这篇关于由未经FindSystemTimeZoneById发现GetSystemTimeZones为什么返回某些时区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!