简体   繁体   中英

IANA/Olson timezone support in C#

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.

[eg 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?

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM