美国境内哪些短时区标识在Java ZoneId中无法识别?

huangapple go评论75阅读模式
英文:

What short timezone ids in the US are not recognized by Java ZoneId?

问题

ZoneId.of(ZoneId.SHORT_IDS.get(place.getTz()))

我没有控制使用哪些时区标识,但我曾以为它总是合法的短时区标识。

我猜情况是我需要问:“根据哪个标准来定义合法的短时区标识?” 例如,我刚刚发现我们有一些记录的时区标识是“AKST”,对应阿拉斯加标准时间。Java的ZoneId类不识别它。

我的解决方法将是手动构建ZoneId,用于我知道需要支持的美国时区标识,但我知道ZoneId不支持这些标识。我的列表现在只有一个条目。还有其他任何“标准”(不管是什么标准)的短时区标识,ZoneId不支持吗?

英文:

I have some code that reads a short timezone id from a record and passes it through this:

ZoneId.of(ZoneId.SHORT_IDS.get(place.getTz()))

I don't have control over what timezone ids are used, but I was under the impression that it would always be a legal short timezone id.

I guess the situation is that I needed to ask "a legal short timezone id according to WHICH STANDARD?" For instance, I just discovered that we have records with a timezone id of "AKST", which corresponds to Alaska standard time. The Java ZoneId class doesn't recognize this.

My workaround will be to manually construct the ZoneId for the timezone ids in the US that I know I will need to support, but which I know ZoneId does not support. My list is now one entry long. Are there any other "standard" (whatever that means) short timezone ids that ZoneId does not support?

答案1

得分: 1

The only "short IDs" that are supported are the ones listed in the Java docs:

EST - -05:00
HST - -10:00
MST - -07:00
ACT - Australia/Darwin
AET - Australia/Sydney
AGT - America/Argentina/Buenos_Aires
ART - Africa/Cairo
AST - America/Anchorage
BET - America/Sao_Paulo
BST - Asia/Dhaka
CAT - Africa/Harare
CNT - America/St_Johns
CST - America/Chicago
CTT - Asia/Shanghai
EAT - Africa/Addis_Ababa
ECT - Europe/Paris
IET - America/Indiana/Indianapolis
IST - Asia/Kolkata
JST - Asia/Tokyo
MIT - Pacific/Apia
NET - Asia/Yerevan
NST - Pacific/Auckland
PLT - Asia/Karachi
PNT - America/Phoenix
PRT - America/Puerto_Rico
PST - America/Los_Angeles
SST - Pacific/Guadalcanal
VST - Asia/Ho_Chi_Minh

"AKST" may be an English time zone abbreviation used by some, but it is not a "Short ID" supported by the Java Time API.

Keep in mind that the mere idea of a "Short ID" is for backwards compatibility with older Java applications where these were already in use. Generally speaking, it's not a great idea to use a few letters to identify a time zone. There are just too many ambiguities. For example, though "CST" stands for "Central Standard Time" and is mapped to America/Chicago on this list, it also stands for "Cuba Standard Time" (America/Havana) and "China Standard Time" (Asia/Shanghai) - neither of which are mapped here.

英文:

The only "short IDs" that are supported are the ones listed in the Java docs:

EST - -05:00
HST - -10:00
MST - -07:00
ACT - Australia/Darwin
AET - Australia/Sydney
AGT - America/Argentina/Buenos_Aires
ART - Africa/Cairo
AST - America/Anchorage
BET - America/Sao_Paulo
BST - Asia/Dhaka
CAT - Africa/Harare
CNT - America/St_Johns
CST - America/Chicago
CTT - Asia/Shanghai
EAT - Africa/Addis_Ababa
ECT - Europe/Paris
IET - America/Indiana/Indianapolis
IST - Asia/Kolkata
JST - Asia/Tokyo
MIT - Pacific/Apia
NET - Asia/Yerevan
NST - Pacific/Auckland
PLT - Asia/Karachi
PNT - America/Phoenix
PRT - America/Puerto_Rico
PST - America/Los_Angeles
SST - Pacific/Guadalcanal
VST - Asia/Ho_Chi_Minh

"AKST" may be an English time zone abbreviation used by some, but it is not a "Short ID" supported by the Java Time API.

Keep in mind that the mere idea of a "Short ID" is for backwards compatibility with older Java applications where these were already in use. Generally speaking, it's not a great idea to use a few letters to identify a time zone. There are just too many ambiguities. For example, though "CST" stands for "Central Standard Time" and is mapped to America/Chicago on this list, it also stands for "Cuba Standard Time" (America/Havana) and "China Standard Time" (Asia/Shanghai) - neither of which are mapped here.

huangapple
  • 本文由 发表于 2020年4月9日 07:38:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/61111712.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定