C# 中的 IANA/Olson 时区支持 [英] IANA/Olson timezone support in C#

查看:19
本文介绍了C# 中的 IANA/Olson 时区支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C# 支持全球不同的时区 ID.请在以下链接中找到 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

时区 ID 在 C# 库函数中用于跨时区转换时间.

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

[例如TimeZoneInfo.ConvertTimeBySystemTimeZoneId("夏威夷标准时间")]

同样,我希望支持 AMERICA/MIQUELON,它不在上面链接中提供的 msdn 列表中.

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?

推荐答案

时区标识符,如 "America/Miquelon" 和您列出的其他(在编辑您的问题之前)来自 IANA 时区数据库.您可以在时区标签维基维基百科上.

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.

在 .NET 中使用这些的最简单和最好的方法是通过 Noda Time 库.

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

例如:

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

这篇关于C# 中的 IANA/Olson 时区支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆