Java 中的时区 ID

2022-01-16 00:00:00 timezone java

我在使用 java TimeZone 时遇到了奇怪的问题..

I'm having weird problem with java TimeZone..

调用 TimeZone.getDefault() 会给出我的本地时区,它的 ID 为GMT+02:00".有趣的是,这个 ID 没有出现在 TimeZone.getAvailableIDs() 提供的列表中.显然我的区域似乎是Etc/GMT+2".

Calling TimeZone.getDefault() gives my local time zone, which has an ID "GMT+02:00". Funny thing is that this ID doesn't appear in a list provided by TimeZone.getAvailableIDs(). Apparently my zone appears to be "Etc/GMT+2".

我正在尝试使用时区填充组合,但无法进行选择,因为 GMT+02:00 不在列表中.有人见过这个问题吗?有什么想法吗?

I'm trying to populate a combo with time zones, but it's impossible to put a selection because GMT+02:00 is not in the list.. Anyone seen this problem? Any ideas?

更新:

底线是 - 不能依赖 ID 字符串,必须使用偏移量,因为显示 ID 可能因系统而异.

The bottom line is - can't rely on ID strings, must go with the offset as display ID's may vary from system to system.

推荐答案

回头看其他一些 SO 问题,这似乎是一个 Java-on-Windows 问题.请看一下这篇文章,尤其是答案 1,它指向一个可以解决您的映射问题的维基百科链接.

Looking back on some other SO questions, this seems to be a Java-on-Windows problem. Please have a look at this article, especially answer 1, which points to a wikipedia link that may solve your mapping issue.

相关文章