多java';s时区';s指向单个joda';日期时区

多java';s时区';s指向单个joda';日期时区,java,timezone,jodatime,Java,Timezone,Jodatime,我使用joda的DateTimeZone及其所有功能 我从第三方得到了java标准时区 然后我将其转换为DateTimeZone,如下所示: TimeZone timeZone = TimeZone.getTimeZone(3rd_party_timezone_string_id); DateTimeZone dateTimeZone = DateTimeZone.forTimeZone(timeZone); 我注意到几个时区映射到同一个DateTimeZone。例如: “澳大利亚/阿德莱德”

我使用joda的DateTimeZone及其所有功能

我从第三方得到了java标准时区

然后我将其转换为DateTimeZone,如下所示:

TimeZone timeZone = TimeZone.getTimeZone(3rd_party_timezone_string_id);
DateTimeZone dateTimeZone = DateTimeZone.forTimeZone(timeZone);
我注意到几个时区映射到同一个DateTimeZone。例如:

“澳大利亚/阿德莱德”->“澳大利亚/阿德莱德”

“澳大利亚/南部”->“澳大利亚/阿德莱德”


那么,我想知道,当我有了DateTimeZone时,如何才能得到映射到它的时区列表?

如果你从IANA获得时区数据和代码(截至2014年11月11日),在
tzdata
中,你可以找到一个
向后的
文件,该文件提供了时区当前名称和旧名称之间的链接

例如,在该文件中,您可以找到您提到的文件:

(...)
Link    Australia/Adelaide  Australia/South
(...)
如果您想拥有这样的ID“映射”,您可以通过
DateTimeZone.forID()
遍历可用的ID并获取当前名称

groovy中的这个小脚本可以满足您的需要(您可以轻松地将其移植到java):

@Grapes(
    @Grab(group='joda-time', module='joda-time', version='2.5')
)

import org.joda.time.*
import org.joda.time.format.*

Map<String, List<String>> equivalentZones = new HashMap<String, List<String>>()

DateTimeZone.getAvailableIDs().each { id ->
    DateTimeZone dtz = DateTimeZone.forID(id)
    zonesForID = equivalentZones.get(dtz.ID, [])
    if (id != dtz.ID) {
        zonesForID << id        
    }
    equivalentZones.put(dtz.ID, zonesForID)
}

equivalentZones.each { k,v ->
    println "$k -> $v"
}
(...)
Africa/Maputo -> [Africa/Blantyre, Africa/Bujumbura, Africa/Gaborone, Africa/Harare, Africa/Kigali, Africa/Lubumbashi, Africa/Lusaka]
(...)
Asia/Shanghai -> [Asia/Chongqing, Asia/Chungking, Asia/Harbin, PRC]
(...)
Australia/Adelaide -> [Australia/South]
(...)
Europe/London -> [Europe/Belfast, Europe/Guernsey, Europe/Isle_of_Man, Europe/Jersey, GB, GB-Eire]
(...)