本文介绍了TimeZone - getAvailableIDs() - 仅过滤 tzdb 时区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

String[] available = TimeZone.getAvailableIDs();

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

The above piece of code in Java returns both TZDB format timezones and Windows format timezones. Is there a way to make it return just the TZDB timezones? For example, some values it returns are,

AST美国/阿达克美国/安克雷奇美国/阿特卡美国/博伊西太平洋标准时间美国/洛杉矶...

AST America/Adak America/Anchorage America/Atka America/Boise PSTAmerica/Los_Angeles...

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

I'm trying to eliminate AST, PST values in it..

推荐答案

听起来您可能应该过滤掉没有 / 的时区 ID.TZDB 包含区域 ID,例如作为 EET 和 EST - 例如,版本 2014a 包含以下不超过 4 个字符的 ID:

It sounds like you should probably just filter out time zone IDs which don't have a / in. TZDB contains zone IDs such as EET and EST - for example, version 2014a contains the follow IDs of 4 characters or fewer:

CET"、古巴"、EET"、EST"、爱尔兰"、GB"、GMT"、GMT0"、HST"、伊朗"、MET"、MST", "NZ", "PRC", "ROC", "ROK", "UCT", "UTC", "W-SU", "WET", "Zulu"

过滤掉任何不包含 / 的东西会过滤掉一点比那多一点......它会删除所有:

Filtering out anything that doesn't contain a / filters out a little bit more than that... it would remove all of:

CET"、CST6CDT"、古巴"、EET"、EST"、EST5EDT"、埃及"、爱尔兰"、GB"、GB-Eire"、GMT"、"GMT+0"、GMT-0"、GMT0"、格林威治"、HST"、香港"、冰岛"、伊朗"、以色列"、牙买加"、日本"、夸贾林", "Libya", "MET", "MST", "MST7MDT", "NZ", "NZ-CHAT", "Navajo", "PRC", "PST8PDT", "Poland", "Portugal", "ROC", "ROK", "Singapore", "Turkey", "UCT", "UTC", "Universal", "W-SU", "WET", "Zulu"

因此请检查该列表 - 如果您不介意丢失任何内容,只需按 / 过滤即可.请注意,上述几乎所有实际上都是其他 ID 的别名.只有以下是不包含 / 的规范 ID:

So check that list - if there's nothing in there that you mind losing, go with just filtering by /.Note that almost all of the above are actually aliases for other IDs. Only the following are canonical IDs which don't contain /:

CET"、CST6CDT"、EET"、EST"、EST5EDT"、HST"、MET"、MST"、MST7MDT"、PST8PDT"、WET"

这篇关于TimeZone - getAvailableIDs() - 仅过滤 tzdb 时区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 04:54