java.util.TimeZone#getDisplayName ( )源码实例Demo

下面列出了java.util.TimeZone#getDisplayName ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: es6draft   文件: TimeZoneInfo.java
@Override
public String getDisplayName(TimeZone tz, long date) {
    DateTimeZone timeZone = toDateTimeZone(tz);
    if (IGNORE_LOCAL_BEFORE_EPOCH) {
        if (date < EPOCH) {
            date = toFirstDateWithNormalizedTime(timeZone, date);
        }
    } else if (IGNORE_LOCAL) {
        if (date <= LAST_LOCAL_TRANSITION) {
            date = toFirstDateWithNormalizedTime(timeZone, date);
        }
    } else if (IGNORE_LMT) {
        if (date <= LAST_LMT_TRANSITION) {
            date = toFirstDateAfterLocalMeanTime(timeZone, date);
        }
    }
    String displayName = timeZone.getNameKey(date);
    if (displayName != null) {
        return displayName;
    }
    boolean daylightSavings = !timeZone.isStandardOffset(date);
    if (!daylightSavings
            && timeZone.getOffset(date) != timeZone.getStandardOffset(System.currentTimeMillis())) {
        daylightSavings = timeZone.nextTransition(date) != date;
    }
    return tz.getDisplayName(daylightSavings, TimeZone.SHORT, Locale.US);
}
 
源代码2 项目: coming   文件: Lang_18_FastDateFormat_s.java
/**
 * <p>Gets the time zone display name, using a cache for performance.</p>
 *
 * @param tz  the zone to query
 * @param daylight  true if daylight savings
 * @param style  the style to use {@code TimeZone.LONG} or {@code TimeZone.SHORT}
 * @param locale  the locale to use
 * @return the textual name of the time zone
 */
static String getTimeZoneDisplay(TimeZone tz, boolean daylight, int style, Locale locale) {
    TimeZoneDisplayKey key = new TimeZoneDisplayKey(tz, daylight, style, locale);
    String value = cTimeZoneDisplayCache.get(key);
    if (value == null) {
        // This is a very slow call, so cache the results.
        value = tz.getDisplayName(daylight, style, locale);
        String prior = cTimeZoneDisplayCache.putIfAbsent(key, value);
        if (prior != null) {
            value= prior;
        }
    }
    return value;
}
 
源代码3 项目: SimFix   文件: 1_FastDateFormat.java
/**
 * <p>Gets the time zone display name, using a cache for performance.</p>
 * 
 * @param tz  the zone to query
 * @param daylight  true if daylight savings
 * @param style  the style to use <code>TimeZone.LONG</code>
 *  or <code>TimeZone.SHORT</code>
 * @param locale  the locale to use
 * @return the textual name of the time zone
 */
static synchronized String getTimeZoneDisplay(TimeZone tz, boolean daylight, int style, Locale locale) {
    Object key = new TimeZoneDisplayKey(tz, daylight, style, locale);
    String value = (String) cTimeZoneDisplayCache.get(key);
    if (value == null) {
        // This is a very slow call, so cache the results.
        value = tz.getDisplayName(daylight, style, locale);
        cTimeZoneDisplayCache.put(key, value);
    }
    return value;
}
 
源代码4 项目: gflogger   文件: FastDateFormat.java
/**
 * <p>Gets the time zone display name, using a cache for performance.</p>
 * 
 * @param tz  the zone to query
 * @param daylight  true if daylight savings
 * @param style  the style to use <code>TimeZone.LONG</code>
 *  or <code>TimeZone.SHORT</code>
 * @param locale  the locale to use
 * @return the textual name of the time zone
 */
static synchronized String getTimeZoneDisplay(TimeZone tz, boolean daylight, int style, Locale locale) {
	// xxx :: GARBAGE !!!
	Object key = new TimeZoneDisplayKey(tz, daylight, style, locale);
	String value = cTimeZoneDisplayCache.get(key);
	if (value == null) {
		// This is a very slow call, so cache the results.
		value = tz.getDisplayName(daylight, style, locale);
		cTimeZoneDisplayCache.put(key, value);
	}
	return value;
}
 
源代码5 项目: TencentKona-8   文件: TestZoneTextPrinterParser.java
public void test_printText() {
    Random r = RandomFactory.getRandom();
    int N = 8;
    Locale[] locales = Locale.getAvailableLocales();
    Set<String> zids = ZoneRulesProvider.getAvailableZoneIds();
    ZonedDateTime zdt = ZonedDateTime.now();

    //System.out.printf("locale==%d, timezone=%d%n", locales.length, zids.size());
    while (N-- > 0) {
        zdt = zdt.withDayOfYear(r.nextInt(365) + 1)
                 .with(ChronoField.SECOND_OF_DAY, r.nextInt(86400));
        for (String zid : zids) {
            if (zid.equals("ROC") || zid.startsWith("Etc/GMT")) {
                continue;      // TBD: match jdk behavior?
            }
            zdt = zdt.withZoneSameLocal(ZoneId.of(zid));
            TimeZone tz = TimeZone.getTimeZone(zid);
            boolean isDST = tz.inDaylightTime(new Date(zdt.toInstant().toEpochMilli()));
            for (Locale locale : locales) {
                String longDisplayName = tz.getDisplayName(isDST, TimeZone.LONG, locale);
                String shortDisplayName = tz.getDisplayName(isDST, TimeZone.SHORT, locale);
                if ((longDisplayName.startsWith("GMT+") && shortDisplayName.startsWith("GMT+"))
                        || (longDisplayName.startsWith("GMT-") && shortDisplayName.startsWith("GMT-"))) {
                    printText(locale, zdt, TextStyle.FULL, tz, tz.getID());
                    printText(locale, zdt, TextStyle.SHORT, tz, tz.getID());
                    continue;
                }
                printText(locale, zdt, TextStyle.FULL, tz,
                        tz.getDisplayName(isDST, TimeZone.LONG, locale));
                printText(locale, zdt, TextStyle.SHORT, tz,
                        tz.getDisplayName(isDST, TimeZone.SHORT, locale));
            }
        }
    }
}
 
源代码6 项目: openjdk-8   文件: TimeZoneNamesTest.java
public static void testTZName( Locale locale, String timezoneName, boolean isDaylight,
                               int nameType, String expectedName ) throws RuntimeException {
    if (!testGeneric) {
        //Construct time zone objects
        TimeZone zone = TimeZone.getTimeZone(timezoneName);
        //Get name from JDK
        String name = zone.getDisplayName(isDaylight, nameType, locale);
        //Check for equality
        if (!name.equals(expectedName))
            throw new RuntimeException( "Time zone ("+timezoneName+") name is incorrect for locale: \""+locale.getDisplayName()
                                        +"\" nameType:"+requestedTestType+" DST:"+isDaylight+" Should be: " +expectedName+" Observed: "+name);
    }
}
 
源代码7 项目: TencentKona-8   文件: HongKong.java
private static void checkTimeZone(String timeZoneID, String expected) {
    TimeZone timeZone = TimeZone.getTimeZone(timeZoneID);
    String actual = timeZone.getDisplayName();
    if (!expected.equals(actual)) {
        throw new RuntimeException();
    }
}
 
源代码8 项目: Telegram   文件: FastDatePrinter.java
/**
 * <p>Gets the time zone display name, using a cache for performance.</p>
 *
 * @param tz       the zone to query
 * @param daylight true if daylight savings
 * @param style    the style to use {@code TimeZone.LONG} or {@code TimeZone.SHORT}
 * @param locale   the locale to use
 * @return the textual name of the time zone
 */
static String getTimeZoneDisplay(final TimeZone tz, final boolean daylight, final int style, final Locale locale) {
    final TimeZoneDisplayKey key = new TimeZoneDisplayKey(tz, daylight, style, locale);
    String value = cTimeZoneDisplayCache.get(key);
    if (value == null) {
        // This is a very slow call, so cache the results.
        value = tz.getDisplayName(daylight, style, locale);
        final String prior = cTimeZoneDisplayCache.putIfAbsent(key, value);
        if (prior != null) {
            value = prior;
        }
    }
    return value;
}
 
源代码9 项目: TelePlus-Android   文件: FastDatePrinter.java
/**
 * <p>Gets the time zone display name, using a cache for performance.</p>
 *
 * @param tz       the zone to query
 * @param daylight true if daylight savings
 * @param style    the style to use {@code TimeZone.LONG} or {@code TimeZone.SHORT}
 * @param locale   the locale to use
 * @return the textual name of the time zone
 */
static String getTimeZoneDisplay(final TimeZone tz, final boolean daylight, final int style, final Locale locale) {
    final TimeZoneDisplayKey key = new TimeZoneDisplayKey(tz, daylight, style, locale);
    String value = cTimeZoneDisplayCache.get(key);
    if (value == null) {
        // This is a very slow call, so cache the results.
        value = tz.getDisplayName(daylight, style, locale);
        final String prior = cTimeZoneDisplayCache.putIfAbsent(key, value);
        if (prior != null) {
            value = prior;
        }
    }
    return value;
}
 
源代码10 项目: coming   文件: Time_19_DateTimeZone_s.java
/**
 * Gets a time zone instance for a JDK TimeZone.
 * <p>
 * DateTimeZone only accepts a subset of the IDs from TimeZone. The
 * excluded IDs are the short three letter form (except UTC). This 
 * method will attempt to convert between time zones created using the
 * short IDs and the full version.
 * <p>
 * This method is not designed to parse time zones with rules created by
 * applications using <code>SimpleTimeZone</code> directly.
 * 
 * @param zone  the zone to convert, null means default
 * @return the DateTimeZone object for the zone
 * @throws IllegalArgumentException if the zone is not recognised
 */
public static DateTimeZone forTimeZone(TimeZone zone) {
    if (zone == null) {
        return getDefault();
    }
    final String id = zone.getID();
    if (id.equals("UTC")) {
        return DateTimeZone.UTC;
    }

    // Convert from old alias before consulting provider since they may differ.
    DateTimeZone dtz = null;
    String convId = getConvertedId(id);
    if (convId != null) {
        dtz = cProvider.getZone(convId);
    }
    if (dtz == null) {
        dtz = cProvider.getZone(id);
    }
    if (dtz != null) {
        return dtz;
    }

    // Support GMT+/-hh:mm formats
    if (convId == null) {
        convId = zone.getDisplayName();
        if (convId.startsWith("GMT+") || convId.startsWith("GMT-")) {
            convId = convId.substring(3);
            int offset = parseOffset(convId);
            if (offset == 0L) {
                return DateTimeZone.UTC;
            } else {
                convId = printOffset(offset);
                return fixedOffsetZone(convId, offset);
            }
        }
    }
    throw new IllegalArgumentException("The datetime zone id '" + id + "' is not recognised");
}
 
源代码11 项目: coming   文件: Elixir_008_s.java
/**
 * <p>Gets the time zone display name, using a cache for performance.</p>
 * 
 * @param tz  the zone to query
 * @param daylight  true if daylight savings
 * @param style  the style to use <code>TimeZone.LONG</code>
 *  or <code>TimeZone.SHORT</code>
 * @param locale  the locale to use
 * @return the textual name of the time zone
 */
static synchronized String getTimeZoneDisplay(TimeZone tz, boolean daylight, int style, Locale locale) {
    Object key = new TimeZoneDisplayKey(tz, daylight, style, locale);
    String value = cTimeZoneDisplayCache.get(key);
    if (value == null) {
        // This is a very slow call, so cache the results.
        value = tz.getDisplayName(daylight, style, locale);
        cTimeZoneDisplayCache.put(key, value);
    }
    return value;
}
 
源代码12 项目: astor   文件: FastDatePrinter.java
/**
 * <p>Gets the time zone display name, using a cache for performance.</p>
 *
 * @param tz  the zone to query
 * @param daylight  true if daylight savings
 * @param style  the style to use {@code TimeZone.LONG} or {@code TimeZone.SHORT}
 * @param locale  the locale to use
 * @return the textual name of the time zone
 */
static String getTimeZoneDisplay(TimeZone tz, boolean daylight, int style, Locale locale) {
    TimeZoneDisplayKey key = new TimeZoneDisplayKey(tz, daylight, style, locale);
    String value = cTimeZoneDisplayCache.get(key);
    if (value == null) {
        // This is a very slow call, so cache the results.
        value = tz.getDisplayName(daylight, style, locale);
        String prior = cTimeZoneDisplayCache.putIfAbsent(key, value);
        if (prior != null) {
            value= prior;
        }
    }
    return value;
}
 
源代码13 项目: spring-tutorial   文件: FormControllerTests.java
private String getTimezone(int year, int month, int day) {
	Calendar calendar = Calendar.getInstance();
	calendar.set(Calendar.YEAR, year);
	calendar.set(Calendar.MONTH, month);
	calendar.set(Calendar.DAY_OF_MONTH, day);
	Date date = calendar.getTime();
	TimeZone timezone = TimeZone.getDefault();
	boolean inDaylight = timezone.inDaylightTime(date);
	return timezone.getDisplayName(inDaylight, TimeZone.SHORT);
}
 
源代码14 项目: coming   文件: Lang_38_FastDateFormat_t.java
/**
 * <p>Gets the time zone display name, using a cache for performance.</p>
 * 
 * @param tz  the zone to query
 * @param daylight  true if daylight savings
 * @param style  the style to use <code>TimeZone.LONG</code>
 *  or <code>TimeZone.SHORT</code>
 * @param locale  the locale to use
 * @return the textual name of the time zone
 */
static synchronized String getTimeZoneDisplay(TimeZone tz, boolean daylight, int style, Locale locale) {
    Object key = new TimeZoneDisplayKey(tz, daylight, style, locale);
    String value = cTimeZoneDisplayCache.get(key);
    if (value == null) {
        // This is a very slow call, so cache the results.
        value = tz.getDisplayName(daylight, style, locale);
        cTimeZoneDisplayCache.put(key, value);
    }
    return value;
}
 
源代码15 项目: coming   文件: Nopol2017_0089_s.java
/**
 * Gets a time zone instance for a JDK TimeZone.
 * <p>
 * DateTimeZone only accepts a subset of the IDs from TimeZone. The
 * excluded IDs are the short three letter form (except UTC). This 
 * method will attempt to convert between time zones created using the
 * short IDs and the full version.
 * <p>
 * This method is not designed to parse time zones with rules created by
 * applications using <code>SimpleTimeZone</code> directly.
 * 
 * @param zone  the zone to convert, null means default
 * @return the DateTimeZone object for the zone
 * @throws IllegalArgumentException if the zone is not recognised
 */
public static DateTimeZone forTimeZone(TimeZone zone) {
    if (zone == null) {
        return getDefault();
    }
    final String id = zone.getID();
    if (id.equals("UTC")) {
        return DateTimeZone.UTC;
    }

    // Convert from old alias before consulting provider since they may differ.
    DateTimeZone dtz = null;
    String convId = getConvertedId(id);
    if (convId != null) {
        dtz = cProvider.getZone(convId);
    }
    if (dtz == null) {
        dtz = cProvider.getZone(id);
    }
    if (dtz != null) {
        return dtz;
    }

    // Support GMT+/-hh:mm formats
    if (convId == null) {
        convId = zone.getDisplayName();
        if (convId.startsWith("GMT+") || convId.startsWith("GMT-")) {
            convId = convId.substring(3);
            int offset = parseOffset(convId);
            if (offset == 0L) {
                return DateTimeZone.UTC;
            } else {
                convId = printOffset(offset);
                return fixedOffsetZone(convId, offset);
            }
        }
    }
    throw new IllegalArgumentException("The datetime zone id '" + id + "' is not recognised");
}
 
源代码16 项目: coming   文件: Arja_00117_t.java
/**
 * <p>Gets the time zone display name, using a cache for performance.</p>
 * 
 * @param tz  the zone to query
 * @param daylight  true if daylight savings
 * @param style  the style to use <code>TimeZone.LONG</code>
 *  or <code>TimeZone.SHORT</code>
 * @param locale  the locale to use
 * @return the textual name of the time zone
 */
static synchronized String getTimeZoneDisplay(TimeZone tz, boolean daylight, int style, Locale locale) {
    Object key = new TimeZoneDisplayKey(tz, daylight, style, locale);
    String value = (String) cTimeZoneDisplayCache.get(key);
    if (value == null) {
        // This is a very slow call, so cache the results.
        value = tz.getDisplayName(daylight, style, locale);
        cTimeZoneDisplayCache.put(key, value);
    }
    return value;
}
 
源代码17 项目: coming   文件: Lang_26_FastDateFormat_t.java
/**
 * <p>Gets the time zone display name, using a cache for performance.</p>
 * 
 * @param tz  the zone to query
 * @param daylight  true if daylight savings
 * @param style  the style to use <code>TimeZone.LONG</code>
 *  or <code>TimeZone.SHORT</code>
 * @param locale  the locale to use
 * @return the textual name of the time zone
 */
static synchronized String getTimeZoneDisplay(TimeZone tz, boolean daylight, int style, Locale locale) {
    Object key = new TimeZoneDisplayKey(tz, daylight, style, locale);
    String value = cTimeZoneDisplayCache.get(key);
    if (value == null) {
        // This is a very slow call, so cache the results.
        value = tz.getDisplayName(daylight, style, locale);
        cTimeZoneDisplayCache.put(key, value);
    }
    return value;
}
 
源代码18 项目: coming   文件: elixir1_one_t.java
/**
 * <p>Gets the time zone display name, using a cache for performance.</p>
 * 
 * @param tz  the zone to query
 * @param daylight  true if daylight savings
 * @param style  the style to use <code>TimeZone.LONG</code>
 *  or <code>TimeZone.SHORT</code>
 * @param locale  the locale to use
 * @return the textual name of the time zone
 */
static synchronized String getTimeZoneDisplay(TimeZone tz, boolean daylight, int style, Locale locale) {
    Object key = new TimeZoneDisplayKey(tz, daylight, style, locale);
    String value = cTimeZoneDisplayCache.get(key);
    if (value == null) {
        // This is a very slow call, so cache the results.
        value = tz.getDisplayName(daylight, style, locale);
        cTimeZoneDisplayCache.put(key, value);
    }
    return value;
}
 
源代码19 项目: es6draft   文件: TimeZoneInfo.java
@Override
public String getDisplayName(TimeZone tz, long date) {
    boolean daylightSavings = tz.inDaylightTime(new Date(date));
    if (!daylightSavings && tz.getOffset(date) != tz.getRawOffset()) {
        daylightSavings = tz.useDaylightTime();
    }
    return tz.getDisplayName(daylightSavings, TimeZone.SHORT, Locale.US);
}
 
源代码20 项目: incubator-pinot   文件: BaseNotificationContent.java
/**
 * Get the timezone in String
 */
protected String getTimezoneString(DateTimeZone dateTimeZone) {
  TimeZone tz = TimeZone.getTimeZone(dateTimeZone.getID());
  return tz.getDisplayName(true, 0);
}