本文整理汇总了Java中java.text.DateFormatSymbols.getZoneStrings方法的典型用法代码示例。如果您正苦于以下问题:Java DateFormatSymbols.getZoneStrings方法的具体用法?Java DateFormatSymbols.getZoneStrings怎么用?Java DateFormatSymbols.getZoneStrings使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.text.DateFormatSymbols
的用法示例。
在下文中一共展示了DateFormatSymbols.getZoneStrings方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getZoneStringsTest
import java.text.DateFormatSymbols; //导入方法依赖的package包/类
@Test
public void getZoneStringsTest() {
DateFormatSymbols dfs = new DateFormatSymbols();
String[][] result = dfs.getZoneStrings();
for (int i = 0; i < 10; i++) {
if (!Arrays.deepEquals(result, dfs.getZoneStrings())) {
return;
}
}
fail("getZoneStrings did not extend in 10 tries; something is likely fishy.");
}
示例2: main
import java.text.DateFormatSymbols; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception
{
DateFormatSymbols symbols = new DateFormatSymbols(Locale.JAPAN);
String[] eras = symbols.getEras();
System.out.println("BC = " + eras[0]);
if (!eras[0].equals(bc)) {
System.out.println("*** Should have been " + bc);
throw new Exception("Error in BC");
}
System.out.println("AD = " + eras[1]);
if (!eras[1].equals(ad)) {
System.out.println("*** Should have been " + ad);
throw new Exception("Error in AD");
}
String[][] zones = symbols.getZoneStrings();
for (int i = 0; i < zones.length; i++) {
if (!"Asia/Tokyo".equals(zones[i][0])) {
continue;
}
System.out.println("Long zone name = " + zones[i][1]);
if (!zones[i][1].equals(jstLong)) {
System.out.println("*** Should have been " + jstLong);
throw new Exception("Error in long TZ name");
}
System.out.println("Short zone name = " + zones[i][2]);
if (!zones[i][2].equals(jstShort)) {
System.out.println("*** Should have been " + jstShort);
throw new Exception("Error in short TZ name");
}
System.out.println("Long zone name = " + zones[i][3]);
if (!zones[i][3].equals(jdtLong)) {
System.out.println("*** Should have been " + jdtLong);
throw new Exception("Error in long TZ name");
}
System.out.println("SHORT zone name = " + zones[i][4]);
if (!zones[i][4].equals(jdtShort)) {
System.out.println("*** Should have been " + jdtShort);
throw new Exception("Error in short TZ name");
}
}
}
示例3: getDisplayName
import java.text.DateFormatSymbols; //导入方法依赖的package包/类
/**
* Returns a localised textual representation of the current value
* of the given field using the specified style. If there is no
* applicable textual representation (e.g. the field has a numeric
* value), then <code>null</code> is returned. If one does exist,
* then the value is obtained from {@link #get(int)} and converted
* appropriately. For example, if the <code>MONTH</code> field is
* requested, then <code>get(MONTH)</code> is called. This is then
* converted to a textual representation based on its value and
* the style requested; if the <code>LONG</code> style is requested
* and the returned value is <code>11</code> from a
* {@link GregorianCalendar} implementation, then <code>"December"</code>
* is returned. By default, a textual representation is available
* for all fields which have an applicable value obtainable from
* {@link java.text.DateFormatSymbols}.
*
* @param field the calendar field whose textual representation should
* be obtained.
* @param style the style to use; either {@link #LONG} or {@link #SHORT}.
* @param locale the locale to use for translation.
* @return the textual representation of the given field in the specified
* style, or <code>null</code> if none is applicable.
* @throws IllegalArgumentException if <code>field</code> or <code>style</code>
* or invalid, or the calendar is non-lenient
* and has invalid values.
* @throws NullPointerException if <code>locale</code> is <code>null</code>.
* @since 1.6
*/
public String getDisplayName(int field, int style, Locale locale)
{
if (field < 0 || field >= FIELD_COUNT)
throw new IllegalArgumentException("The field value, " + field +
", is invalid.");
if (style != SHORT && style != LONG)
throw new IllegalArgumentException("The style must be either " +
"short or long.");
if (field == YEAR || field == WEEK_OF_YEAR ||
field == WEEK_OF_MONTH || field == DAY_OF_MONTH ||
field == DAY_OF_YEAR || field == DAY_OF_WEEK_IN_MONTH ||
field == HOUR || field == HOUR_OF_DAY || field == MINUTE ||
field == SECOND || field == MILLISECOND)
return null;
int value = get(field);
DateFormatSymbols syms = DateFormatSymbols.getInstance(locale);
if (field == ERA)
return syms.getEras()[value];
if (field == MONTH)
if (style == LONG)
return syms.getMonths()[value];
else
return syms.getShortMonths()[value];
if (field == DAY_OF_WEEK)
if (style == LONG)
return syms.getWeekdays()[value];
else
return syms.getShortWeekdays()[value];
if (field == AM_PM)
return syms.getAmPmStrings()[value];
if (field == ZONE_OFFSET)
if (style == LONG)
return syms.getZoneStrings()[value][1];
else
return syms.getZoneStrings()[value][2];
if (field == DST_OFFSET)
if (style == LONG)
return syms.getZoneStrings()[value][3];
else
return syms.getZoneStrings()[value][4];
throw new InternalError("Failed to resolve field " + field +
" with style " + style + " for locale " +
locale);
}