IANA/Olson timezone support in C#

折月煮酒 提交于 2021-02-10 06:08:11

问题


C# supports different timezone id's across the globe. Please find list of time zones that are being supported by C# in below link:

https://msdn.microsoft.com/en-us/library/gg154758.aspx

The timezone id's are used in C# library functions to convert times across the timezones.

[e.g. TimeZoneInfo.ConvertTimeBySystemTimeZoneId("Hawaiian Standard Time")]

Similarly I want support for AMERICA/MIQUELON, which is not present in the msdn list provided in above link.

Can somebody please provide workaround for this specific timezone?


回答1:


Time zone identifiers like "America/Miquelon" and the others you listed (before editing your question) are from the IANA time zone database. You can read more in the timezone tag wiki and on Wikipedia.

Note that they are usually presented in mixed case form, rather than in all capital letters.

The easiest and best way to work with these in .NET is via the Noda Time library.

For example:

DateTimeZone tz = DateTimeZoneProviders.Tzdb["America/Miquelon"];
Instant now = SystemClock.Instance.Now;
ZonedDateTime converted = now.InZone(tz);


来源:https://stackoverflow.com/questions/30864731/iana-olson-timezone-support-in-c-sharp

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