System.TimeZoneNotFoundException: 'The time zone ID 'Asia/Jerusalem' was not found on the local computer.' [closed]

隐身守侯 提交于 2020-01-26 03:58:06

问题


can somebody help me? I tried everything!


回答1:


"Asia/Jerusalem" is an ID in the style used by the IANA time zone database (aka tzdb or tz or zoneinfo). Windows uses its own time zone IDs which are very different.

If you want to use IANA time zones in a cross-platform way, I'd suggest using the Noda Time project which I maintain, instead of TimeZoneInfo.

Additionally, values such as "number of seconds since the epoch" are normally not time-zone-sensitive; the Unix epoch is fixed at 1970-01-01T00:00:00 UTC, not "midnight on January 1st 1970 local time on a per time zone basis". While such a value can be useful (we have the concept internally in Noda Time) I would think very carefully before using that. Ideally, stick to a higher level abstraction - in Noda Time, I'd suggest using ZonedDateTime, Instant or LocalDateTime, depending on your requirements.




回答2:


I will look it up, but I am guessing it calls or uses the same data as TimeZoneInfo.GetSystemTimeZones(). As the name implies, not all Timezones are avalible on all computers.

Edit: I could confirm it. GetSystemTimeZones is actually returns a ReadonlyCollection, Built from the Registry with some Caching. And if I read it right, it will not exist at all (Conditional Compilation) if you do not have the FEATURE_WIN32_REGISTRY Flag set. FindSystemTimeZoneById() has the same rules and limitations, and indeed accesses the same cache.

.NET in general tries to use the timezone rules and conversions that the Operating System has. So it is quite possible this Timezone does not exist, or is there under another name. And here it seems to be limited 100% to what the Windows Registery says.



来源:https://stackoverflow.com/questions/59369878/system-timezonenotfoundexception-the-time-zone-id-asia-jerusalem-was-not-fou

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!