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


Java DateFormatSymbols.getInstance方法代码示例

本文整理汇总了Java中java.text.DateFormatSymbols.getInstance方法的典型用法代码示例。如果您正苦于以下问题:Java DateFormatSymbols.getInstance方法的具体用法?Java DateFormatSymbols.getInstance怎么用?Java DateFormatSymbols.getInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.text.DateFormatSymbols的用法示例。


在下文中一共展示了DateFormatSymbols.getInstance方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getStandaloneMonthName

import java.text.DateFormatSymbols; //导入方法依赖的package包/类
/**
 * getStandaloneMonthName, This returns a "standalone version" month name for the specified
 * month, in the specified locale. In some languages, including Russian and Czech, the
 * standalone version of the month name is different from the version of the month name you
 * would use as part of a full date. (Is different from the formatting version).
 *
 * This tries to get the standalone version first. If no mapping is found for a standalone
 * version (Presumably because the supplied language has no standalone version), then this will
 * return the formatting version of the month name.
 */
private static String getStandaloneMonthName(Month month, Locale locale, boolean capitalize,
        boolean shortVersion) {
    // Attempt to get the standalone version of the month name.
    TextStyle style = (shortVersion) ? TextStyle.SHORT_STANDALONE : TextStyle.FULL_STANDALONE;
    String monthName = month.getDisplayName(style, locale);
    String monthNumber = "" + month.getValue();
    // If no mapping was found, then get the "formatting version" of the month name.
    if (monthName.equals(monthNumber)) {
        DateFormatSymbols dateSymbols = DateFormatSymbols.getInstance(locale);
        if (shortVersion) {
            monthName = dateSymbols.getShortMonths()[month.getValue() - 1];
        } else {
            monthName = dateSymbols.getMonths()[month.getValue() - 1];
        }
    }
    // If needed, capitalize the month name.
    if ((capitalize) && (monthName != null) && (monthName.length() > 0)) {
        monthName = monthName.substring(0, 1).toUpperCase(locale) + monthName.substring(1);
    }
    return monthName;
}
 
开发者ID:LGoodDatePicker,项目名称:LGoodDatePicker,代码行数:32,代码来源:ExtraDateStrings.java

示例2: getFormattingMonthName

import java.text.DateFormatSymbols; //导入方法依赖的package包/类
/**
 * getFormattingMonthName, This returns a "formatting version" month name for the specified
 * month, in the specified locale. In some languages, including Russian and Czech, the
 * standalone version of the month name is different from the version of the month name you
 * would use as part of a full date. (Is different from the formatting version).
 */
private static String getFormattingMonthName(Month month, Locale locale, boolean capitalize,
        boolean shortVersion) {
    // Get the "formatting version" of the month name.
    DateFormatSymbols dateSymbols = DateFormatSymbols.getInstance(locale);
    String monthName;
    if (shortVersion) {
        monthName = dateSymbols.getShortMonths()[month.getValue() - 1];
    } else {
        monthName = dateSymbols.getMonths()[month.getValue() - 1];
    }
    // If needed, capitalize the month name.
    if ((capitalize) && (monthName != null) && (monthName.length() > 0)) {
        monthName = monthName.substring(0, 1).toUpperCase(locale) + monthName.substring(1);
    }
    return monthName;
}
 
开发者ID:LGoodDatePicker,项目名称:LGoodDatePicker,代码行数:23,代码来源:ExtraDateStrings.java

示例3: getDisplayNameArray

import java.text.DateFormatSymbols; //导入方法依赖的package包/类
private String[] getDisplayNameArray(int field, int style, Locale locale) {
	if (field < 0 || field >= FIELD_COUNT) {
		throw new IllegalArgumentException("bad field " + field);
	}
	checkStyle(style);
	DateFormatSymbols dfs = DateFormatSymbols.getInstance(locale);
	switch (field) {
		case AM_PM:
			return dfs.getAmPmStrings();
		case DAY_OF_WEEK:
			return (style == LONG) ? dfs.getWeekdays() : dfs.getShortWeekdays();
		case ERA:
			return dfs.getEras();
		case MONTH:
			return (style == LONG) ? dfs.getMonths() : dfs.getShortMonths();
	}
	return null;
}
 
开发者ID:jtransc,项目名称:jtransc,代码行数:19,代码来源:Calendar.java

示例4: setCellHeaderWeekDays

import java.text.DateFormatSymbols; //导入方法依赖的package包/类
public static void setCellHeaderWeekDays(final RemoteViews headerRowRv, final int firstDayOfWeek, final Context context) {

        DateFormatSymbols dfs = DateFormatSymbols.getInstance();
        String[] weekdays = dfs.getShortWeekdays();

        ThemesUtil.Theme theme = ConfigurationUtil.getTheme(context);

        for (int i = 0; i < Calendar.DAY_OF_WEEK; i++) {

            RemoteViews rv;
            int current = (firstDayOfWeek + i) % Calendar.DAY_OF_WEEK == 0 ? firstDayOfWeek + i : (firstDayOfWeek + i) % Calendar.DAY_OF_WEEK;
            if (current == Calendar.SATURDAY) {
                rv = setSpecificWeekDay(context, weekdays[current], theme.getCellHeaderSaturday());
            } else if (current == Calendar.SUNDAY) {
                rv = setSpecificWeekDay(context, weekdays[current], theme.getCellHeaderSunday());
            } else {
                rv = setSpecificWeekDay(context, weekdays[current], theme.getCellHeader());
            }
            headerRowRv.addView(R.id.row_container, rv);
        }
    }
 
开发者ID:mvmike,项目名称:min-cal-widget,代码行数:22,代码来源:WeekDayHeaderUtil.java

示例5: getDisplayNamesImpl

import java.text.DateFormatSymbols; //导入方法依赖的package包/类
private Map<String,Integer> getDisplayNamesImpl(int field, int style, Locale locale) {
    DateFormatSymbols symbols = DateFormatSymbols.getInstance(locale);
    String[] strings = getFieldStrings(field, style, symbols);
    if (strings != null) {
        Map<String,Integer> names = new HashMap<>();
        for (int i = 0; i < strings.length; i++) {
            if (strings[i].length() == 0) {
                continue;
            }
            names.put(strings[i], i);
        }
        return names;
    }
    return null;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:16,代码来源:Calendar.java

示例6: main

import java.text.DateFormatSymbols; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    System.setSecurityManager(new SecurityManager());

    DateFormatSymbols syms = DateFormatSymbols.getInstance(Locale.GERMAN);
    if (!"Oktober".equals(syms.getMonths()[Calendar.OCTOBER])) {
        throw new RuntimeException("Test failed (FormatData)");
    }

    String s = HijrahChronology.INSTANCE.getDisplayName(TextStyle.FULL, Locale.GERMAN);
    if (!s.contains("Islamischer Kalender")) {
        throw new RuntimeException("Test failed (JavaTimeSupplementary)");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:Bug8152817.java

示例7: createDateFormat

import java.text.DateFormatSymbols; //导入方法依赖的package包/类
/**
 * Get local-Date-Format.
 */

private static DateFormatSymbols createDateFormat(Locale... locales) {
	return DateFormatSymbols
			.getInstance((locales != null && locales.length == 1) ? locales[0]
					: getLocale());
}
 
开发者ID:legend0702,项目名称:zhq,代码行数:10,代码来源:LocaleUtil.java

示例8: setSizeOfMonthYearPanel

import java.text.DateFormatSymbols; //导入方法依赖的package包/类
/**
 * setSizeOfMonthYearPanel, This sets the size of the panel at the top of the calendar that
 * holds the month and the year label. The size is calculated from the largest month name (in
 * pixels), that exists in locale and language that is being used by the date picker.
 */
private void setSizeOfMonthYearPanel() {
    // Skip this function if the settings have not been applied.
    if (settings == null) {
        return;
    }
    // Get the font metrics object.
    Font font = labelMonth.getFont();
    Canvas canvas = new Canvas();
    FontMetrics metrics = canvas.getFontMetrics(font);
    // Calculate the preferred height for the month and year panel.
    int heightNavigationButtons = buttonPreviousYear.getPreferredSize().height;
    int preferredHeightMonthLabel = labelMonth.getPreferredSize().height;
    int preferredHeightYearLabel = labelYear.getPreferredSize().height;
    int monthFontHeight = metrics.getHeight();
    int monthFontHeightWithPadding = monthFontHeight + 2;
    int panelHeight = Math.max(monthFontHeightWithPadding, Math.max(preferredHeightMonthLabel,
            Math.max(preferredHeightYearLabel, heightNavigationButtons)));
    // Get the length of the longest translated month string (in pixels).
    DateFormatSymbols symbols = DateFormatSymbols.getInstance(settings.getLocale());
    String[] allLocalMonths = symbols.getMonths();
    int longestMonthPixels = 0;
    for (String month : allLocalMonths) {
        int monthPixels = metrics.stringWidth(month);
        longestMonthPixels = (monthPixels > longestMonthPixels) ? monthPixels : longestMonthPixels;
    }
    int yearPixels = metrics.stringWidth("_2000");
    // Calculate the size of a box to hold the text with some padding.
    Dimension size = new Dimension(longestMonthPixels + yearPixels + 12, panelHeight);
    // Set the monthAndYearPanel to the appropriate constant size.
    monthAndYearOuterPanel.setMinimumSize(size);
    monthAndYearOuterPanel.setPreferredSize(size);
    // monthAndYearOuterPanel.setMaximumSize(size);
    // Redraw the panel.
    this.doLayout();
    this.validate();
}
 
开发者ID:LGoodDatePicker,项目名称:LGoodDatePicker,代码行数:42,代码来源:CalendarPanel.java

示例9: getNames

import java.text.DateFormatSymbols; //导入方法依赖的package包/类
public static String[] getNames(Resources r)
{
	DateFormatSymbols symbols = DateFormatSymbols.getInstance();
	String[] result = Arrays.copyOf(toIso8601Order(symbols.getWeekdays()),WEEKDAYS_VALUES);
	result[PUBLIC_HOLIDAY] = r.getString(R.string.quest_openingHours_public_holidays);
	return result;
}
 
开发者ID:westnordost,项目名称:StreetComplete,代码行数:8,代码来源:Weekdays.java

示例10: getShortNames

import java.text.DateFormatSymbols; //导入方法依赖的package包/类
public static String[] getShortNames(Resources r)
{
	DateFormatSymbols symbols = DateFormatSymbols.getInstance();
	String[] result = Arrays.copyOf(toIso8601Order(symbols.getShortWeekdays()),WEEKDAYS_VALUES);
	result[PUBLIC_HOLIDAY] = r.getString(R.string.quest_openingHours_public_holidays_short);
	return result;
}
 
开发者ID:westnordost,项目名称:StreetComplete,代码行数:8,代码来源:Weekdays.java

示例11: getDisplayName

import java.text.DateFormatSymbols; //导入方法依赖的package包/类
/**
 * Returns the string representation of the calendar
 * <code>field</code> value in the given <code>style</code> and
 * <code>locale</code>.  If no string representation is
 * applicable, <code>null</code> is returned. This method calls
 * {@link Calendar#get(int) get(field)} to get the calendar
 * <code>field</code> value if the string representation is
 * applicable to the given calendar <code>field</code>.
 *
 * <p>For example, if this <code>Calendar</code> is a
 * <code>GregorianCalendar</code> and its date is 2005-01-01, then
 * the string representation of the {@link #MONTH} field would be
 * "January" in the long style in an English locale or "Jan" in
 * the short style. However, no string representation would be
 * available for the {@link #DAY_OF_MONTH} field, and this method
 * would return <code>null</code>.
 *
 * <p>The default implementation supports the calendar fields for
 * which a {@link DateFormatSymbols} has names in the given
 * <code>locale</code>.
 *
 * @param field
 *        the calendar field for which the string representation
 *        is returned
 * @param style
 *        the style applied to the string representation; one of {@link
 *        #SHORT_FORMAT} ({@link #SHORT}), {@link #SHORT_STANDALONE},
 *        {@link #LONG_FORMAT} ({@link #LONG}), {@link #LONG_STANDALONE},
 *        {@link #NARROW_FORMAT}, or {@link #NARROW_STANDALONE}.
 * @param locale
 *        the locale for the string representation
 *        (any calendar types specified by {@code locale} are ignored)
 * @return the string representation of the given
 *        {@code field} in the given {@code style}, or
 *        {@code null} if no string representation is
 *        applicable.
 * @exception IllegalArgumentException
 *        if {@code field} or {@code style} is invalid,
 *        or if this {@code Calendar} is non-lenient and any
 *        of the calendar fields have invalid values
 * @exception NullPointerException
 *        if {@code locale} is null
 * @since 1.6
 */
public String getDisplayName(int field, int style, Locale locale) {
    if (!checkDisplayNameParams(field, style, SHORT, NARROW_FORMAT, locale,
                        ERA_MASK|MONTH_MASK|DAY_OF_WEEK_MASK|AM_PM_MASK)) {
        return null;
    }

    // the standalone and narrow styles are supported only through CalendarDataProviders.
    if (isStandaloneStyle(style) || isNarrowStyle(style)) {
        return CalendarDataUtility.retrieveFieldValueName(getCalendarType(),
                                                          field, get(field),
                                                          style, locale);
    }

    DateFormatSymbols symbols = DateFormatSymbols.getInstance(locale);
    String[] strings = getFieldStrings(field, style, symbols);
    if (strings != null) {
        int fieldValue = get(field);
        if (fieldValue < strings.length) {
            return strings[fieldValue];
        }
    }
    return null;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:68,代码来源:Calendar.java

示例12: 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);
}
 
开发者ID:vilie,项目名称:javify,代码行数:75,代码来源:Calendar.java


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