TimeZone - getAvailableIDs() - 仅过滤tzdb时区

时间:2014-10-02 21:25:11

标签: java timezone

String[] available = TimeZone.getAvailableIDs();

Java中的上述代码片段返回TZDB格式时区和Windows格式时区。有没有办法让它只返回TZDB时区?例如,它返回的一些值是

AST 美洲/埃达克 美国/安克雷奇 美洲/阿特卡 America / Boise PST 美洲/洛杉矶...

我正在尝试消除其中的AST,PST值..

1 个答案:

答案 0 :(得分:2)

听起来你应该只过滤掉没有/的时区ID .TZDB包含区域ID,例如EET和EST - 例如,版本2014a包含以下ID 4个字符或更少:

  

" CET","古巴"," EET"," EST"," Eire",&# 34; GB"," GMT"," GMT0"," HST","伊朗"," MET&#34 ;," MST"," NZ"," PRC"," ROC"," ROK",&#34 ; UCT"," UTC"," W-SU"," WET"," Zulu"

过滤掉任何不包含/内容的位的内容...将删除所有内容:

  

" CET"," CST6CDT","古巴"," EET"," EST",&# 34; EST5EDT","埃及"," Eire"," GB"," GB-Eire"," GMT& #34;," GMT + 0"," GMT-0"," GMT0","格林威治"," HST&# 34;,"香港","冰岛","伊朗","以色列","牙买加",&# 34;日本"," Kwajalein","利比亚"," MET"," MST"," MST7MDT&#34 ;," NZ"," NZ-CHAT"," Navajo"," PRC"," PST8PDT",& #34;波兰","葡萄牙"," ROC"," ROK","新加坡","土耳其&# 34;," UCT"," UTC"," Universal"," W-SU"," WET", "祖鲁"

所以请检查一下这个列表 - 如果那里没有你介意丢失的东西,那么只需按/进行过滤即可。 请注意,上述所有几乎都是其他ID的别名。只有以下是不包含/的规范ID:

  

" CET"," CST6CDT"," EET"," EST"," EST5EDT",&# 34; HST"," MET"," MST"," MST7MDT"," PST8PDT"," WET&#34 ;