本文整理汇总了Java中com.ibm.icu.util.TimeZone.getCanonicalID方法的典型用法代码示例。如果您正苦于以下问题:Java TimeZone.getCanonicalID方法的具体用法?Java TimeZone.getCanonicalID怎么用?Java TimeZone.getCanonicalID使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.ibm.icu.util.TimeZone
的用法示例。
在下文中一共展示了TimeZone.getCanonicalID方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createTimeZone
import com.ibm.icu.util.TimeZone; //导入方法依赖的package包/类
/**
* Creates an instance of JavaTimeZone with the given timezone ID.
* @param id A timezone ID, either a system ID or a custom ID.
* @return An instance of JavaTimeZone for the given ID, or null
* when the ID cannot be understood.
*/
public static JavaTimeZone createTimeZone(String id) {
java.util.TimeZone jtz = null;
if (AVAILABLESET.contains(id)) {
jtz = java.util.TimeZone.getTimeZone(id);
}
if (jtz == null) {
// Use ICU's canonical ID mapping
boolean[] isSystemID = new boolean[1];
String canonicalID = TimeZone.getCanonicalID(id, isSystemID);
if (isSystemID[0] && AVAILABLESET.contains(canonicalID)) {
jtz = java.util.TimeZone.getTimeZone(canonicalID);
}
}
if (jtz == null) {
return null;
}
return new JavaTimeZone(jtz, id);
}
示例2: getZoneStrings
import com.ibm.icu.util.TimeZone; //导入方法依赖的package包/类
/**
* Returns time zone strings.
* <p>
* The array returned by this API is a two dimensional String array and
* each row contains at least following strings:
* <ul>
* <li>ZoneStrings[n][0] - System time zone ID
* <li>ZoneStrings[n][1] - Long standard time display name
* <li>ZoneStrings[n][2] - Short standard time display name
* <li>ZoneStrings[n][3] - Long daylight saving time display name
* <li>ZoneStrings[n][4] - Short daylight saving time display name
* </ul>
* When a localized display name is not available, the corresponding
* array element will be <code>null</code>.
* <p>
* <b>Note</b>: ICU implements the time zone display name formatting algorithm
* specified by <a href="http://www.unicode.org/reports/tr35/">UTS#35 Unicode
* Locale Data Markup Language(LDML)</a>. The algorithm supports historic
* display name changes and various different types of names not available in
* {@link java.text.DateFormatSymbols#getZoneStrings()}. For accessing the full
* set of time zone string data used by ICU implementation, you should use
* {@link TimeZoneNames} APIs instead.
*
* @return the time zone strings.
* @stable ICU 2.0
*/
public String[][] getZoneStrings() {
if (zoneStrings != null) {
return duplicate(zoneStrings);
}
String[] tzIDs = TimeZone.getAvailableIDs();
TimeZoneNames tznames = TimeZoneNames.getInstance(validLocale);
tznames.loadAllDisplayNames();
NameType types[] = {
NameType.LONG_STANDARD, NameType.SHORT_STANDARD,
NameType.LONG_DAYLIGHT, NameType.SHORT_DAYLIGHT
};
long now = System.currentTimeMillis();
String[][] array = new String[tzIDs.length][5];
for (int i = 0; i < tzIDs.length; i++) {
String canonicalID = TimeZone.getCanonicalID(tzIDs[i]);
if (canonicalID == null) {
canonicalID = tzIDs[i];
}
array[i][0] = tzIDs[i];
tznames.getDisplayNames(canonicalID, types, now, array[i], 1);
}
zoneStrings = array;
return zoneStrings;
}