本文整理汇总了Java中sun.util.locale.provider.TimeZoneNameUtility类的典型用法代码示例。如果您正苦于以下问题:Java TimeZoneNameUtility类的具体用法?Java TimeZoneNameUtility怎么用?Java TimeZoneNameUtility使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TimeZoneNameUtility类属于sun.util.locale.provider包,在下文中一共展示了TimeZoneNameUtility类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getZoneStringsImpl
import sun.util.locale.provider.TimeZoneNameUtility; //导入依赖的package包/类
private String[][] getZoneStringsImpl(boolean needsCopy) {
if (zoneStrings == null) {
zoneStrings = TimeZoneNameUtility.getZoneStrings(locale);
}
if (!needsCopy) {
return zoneStrings;
}
int len = zoneStrings.length;
String[][] aCopy = new String[len][];
for (int i = 0; i < len; i++) {
aCopy[i] = Arrays.copyOf(zoneStrings[i], zoneStrings[i].length);
}
return aCopy;
}
示例2: getDisplayName
import sun.util.locale.provider.TimeZoneNameUtility; //导入依赖的package包/类
private String getDisplayName(String id, int type, Locale locale) {
if (textStyle == TextStyle.NARROW) {
return null;
}
String[] names;
SoftReference<Map<Locale, String[]>> ref = cache.get(id);
Map<Locale, String[]> perLocale = null;
if (ref == null || (perLocale = ref.get()) == null ||
(names = perLocale.get(locale)) == null) {
names = TimeZoneNameUtility.retrieveDisplayNames(id, locale);
if (names == null) {
return null;
}
names = Arrays.copyOfRange(names, 0, 7);
names[5] =
TimeZoneNameUtility.retrieveGenericDisplayName(id, TimeZone.LONG, locale);
if (names[5] == null) {
names[5] = names[0]; // use the id
}
names[6] =
TimeZoneNameUtility.retrieveGenericDisplayName(id, TimeZone.SHORT, locale);
if (names[6] == null) {
names[6] = names[0];
}
if (perLocale == null) {
perLocale = new ConcurrentHashMap<>();
}
perLocale.put(locale, names);
cache.put(id, new SoftReference<>(perLocale));
}
switch (type) {
case STD:
return names[textStyle.zoneNameStyleIndex() + 1];
case DST:
return names[textStyle.zoneNameStyleIndex() + 3];
}
return names[textStyle.zoneNameStyleIndex() + 5];
}
示例3: test
import sun.util.locale.provider.TimeZoneNameUtility; //导入依赖的package包/类
private static void test(String tzid, int style, Locale locale, String expected) {
// No public API to get generic time zone names (JDK 8)
String got = TimeZoneNameUtility.retrieveGenericDisplayName(tzid, style, locale);
if (!expected.equals(got)) {
System.err.printf("test: tzid=%s, locale=%s, style=%d, got=\"%s\", expected=\"%s\"%n",
tzid, locale, style, got, expected);
errors++;
}
}
示例4: testGenericTZName
import sun.util.locale.provider.TimeZoneNameUtility; //导入依赖的package包/类
public static void testGenericTZName( Locale locale, String timezoneName,
int nameType, String expectedName ) throws RuntimeException {
if (testGeneric) {
String genericName = TimeZoneNameUtility.retrieveGenericDisplayName(timezoneName, nameType, locale);
//Check for equality
if (!genericName.equals(expectedName))
throw new RuntimeException( "Time zone ("+timezoneName+") name is incorrect for locale \""+locale.getDisplayName()
+"\" nameType: Generic"+"("+nameType+") Should be: " +expectedName+" Observed: "+genericName);
}
}
示例5: getDisplayName
import sun.util.locale.provider.TimeZoneNameUtility; //导入依赖的package包/类
/**
* Returns a name in the specified {@code style} of this {@code TimeZone}
* suitable for presentation to the user in the specified {@code
* locale}. If the specified {@code daylight} is {@code true}, a Daylight
* Saving Time name is returned (even if this {@code TimeZone} doesn't
* observe Daylight Saving Time). Otherwise, a Standard Time name is
* returned.
*
* <p>When looking up a time zone name, the {@linkplain
* ResourceBundle.Control#getCandidateLocales(String,Locale) default
* <code>Locale</code> search path of <code>ResourceBundle</code>} derived
* from the specified {@code locale} is used. (No {@linkplain
* ResourceBundle.Control#getFallbackLocale(String,Locale) fallback
* <code>Locale</code>} search is performed.) If a time zone name in any
* {@code Locale} of the search path, including {@link Locale#ROOT}, is
* found, the name is returned. Otherwise, a string in the
* <a href="#NormalizedCustomID">normalized custom ID format</a> is returned.
*
* @param daylight {@code true} specifying a Daylight Saving Time name, or
* {@code false} specifying a Standard Time name
* @param style either {@link #LONG} or {@link #SHORT}
* @param locale the locale in which to supply the display name.
* @return the human-readable name of this time zone in the given locale.
* @exception IllegalArgumentException if {@code style} is invalid.
* @exception NullPointerException if {@code locale} is {@code null}.
* @since 1.2
* @see java.text.DateFormatSymbols#getZoneStrings()
*/
public String getDisplayName(boolean daylight, int style, Locale locale) {
if (style != SHORT && style != LONG) {
throw new IllegalArgumentException("Illegal style: " + style);
}
String id = getID();
String name = TimeZoneNameUtility.retrieveDisplayName(id, daylight, style, locale);
if (name != null) {
return name;
}
if (id.startsWith("GMT") && id.length() > 3) {
char sign = id.charAt(3);
if (sign == '+' || sign == '-') {
return id;
}
}
int offset = getRawOffset();
if (daylight) {
offset += getDSTSavings();
}
return ZoneInfoFile.toCustomID(offset);
}
示例6: getDisplayNames
import sun.util.locale.provider.TimeZoneNameUtility; //导入依赖的package包/类
private static String[] getDisplayNames(String id, Locale locale) {
return TimeZoneNameUtility.retrieveDisplayNames(id, locale);
}