当前位置: 首页>>代码示例>>Java>>正文


Java TimeZone.getCanonicalID方法代码示例

本文整理汇总了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);
}
 
开发者ID:abhijitvalluri,项目名称:fitnotifications,代码行数:29,代码来源:JavaTimeZone.java

示例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;
}
 
开发者ID:abhijitvalluri,项目名称:fitnotifications,代码行数:54,代码来源:DateFormatSymbols.java


注:本文中的com.ibm.icu.util.TimeZone.getCanonicalID方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。