将IANA / Olson时区数据库映射到缩写(例如EST,PST等) [英] Mapping IANA/Olson timezone database to abbreviations (like EST, PST, etc)

查看:273
本文介绍了将IANA / Olson时区数据库映射到缩写(例如EST,PST等)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将IANA / Olson时区ID映射到缩写,例如EST,PST等。

I need to map IANA/Olson timezone id to abbreviations, like EST, PST, etc.

我知道这不是一对一的映射,例如,对于EST,有很多IANA时区。

I understand that this is not 1-to-1 mapping and that, for example, for EST there are quite a bunch of IANA timezones.

是否可以使用某种数据库/映射?

Is there some kind of database/mapping I can use for this?

PS:最好使用JavaScript解决方案,但希望能帮助我建立此映射的任何信息( IANA时区ID->缩写)。

PS: JavaScript solution is preferable, but any info that could help me to build this mapping (IANA timezone id -> abbreviation) is appreciated.

推荐答案

IANA TZDB源数据确实已经有缩写,但是必须针对相关日期进行计算。您可以在的示例数据此处中看到它。 Zone.FORMAT Rule.LETTER / S 列。

The IANA TZDB source data does have abbreviations already, but they have to be computed for the date in question. You can see it in the example data here, in the Zone.FORMAT and Rule.LETTER/S columns.

由于时区缩写像 CST 可能会含糊不清,仅建议您使用它们向人类展示。千万不要尝试将它们用于另一个方向,因为大多数实现只会识别其中的少数几个,而且它们往往仅对美国有效。

Since time zone abbreviations like CST can be ambiguous, it is only recommended you use them for display to a human. Never attempt to use them going the other direction, because only a few will be recognized by most implementations, and they tend to be valid only for the USA.

有关可以为您执行此操作的代码,请查看我的答案中使用以下操作的代码的下半部分.Net中的 Noda时间。 (上半部分是关于先从Windows区域转换为IANA区域,这是您不需要的。)

Since you asked for code that could do this for you, look at the bottom half of the code in my answer of how to do this using Noda Time in .Net. (The top half is about translating from a Windows zone to an IANA zone first, which you don't need.)

您可以查看用于JavaScript的多个TZDB库,但是我不确定是否有任何直接公开缩写数据的地方。此外,这么小的东西有点重。

You could look at one of the several TZDB libraries for JavaScript, but I'm not sure if any directly expose the abbreviation data or not. Besides, that's a bit heavy for something so small.

这篇关于将IANA / Olson时区数据库映射到缩写(例如EST,PST等)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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