java.text.DateFormatSymbols#getMonths ( )源码实例Demo

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

源代码1 项目: openstock   文件: MonthDateFormat.java
/**
 * Creates a new formatter.
 *
 * @param zone  the time zone used to extract the month and year from dates
 *              passed to this formatter (<code>null</code> not permitted).
 * @param locale  the locale used to determine the month names
 *                (<code>null</code> not permitted).
 * @param chars  the maximum number of characters to use from the month
 *               names, or zero to indicate that the entire month name
 *               should be used.
 * @param showYear  an array of flags that control whether or not the
 *                  year is displayed for a particular month.
 * @param yearFormatter  the year formatter.
 */
public MonthDateFormat(TimeZone zone, Locale locale, int chars,
                       boolean[] showYear, DateFormat yearFormatter) {
    ParamChecks.nullNotPermitted(locale, "locale");
    DateFormatSymbols dfs = new DateFormatSymbols(locale);
    String[] monthsFromLocale = dfs.getMonths();
    this.months = new String[12];
    for (int i = 0; i < 12; i++) {
        if (chars > 0) {
            this.months[i] = monthsFromLocale[i].substring(0,
                    Math.min(chars, monthsFromLocale[i].length()));
        }
        else {
            this.months[i] = monthsFromLocale[i];
        }
    }
    this.calendar = new GregorianCalendar(zone);
    this.showYear = showYear;
    this.yearFormatter = yearFormatter;

    // the following is never used, but it seems that DateFormat requires
    // it to be non-null.  It isn't well covered in the spec, refer to
    // bug parade 5061189 for more info.
    this.numberFormat = NumberFormat.getNumberInstance();
}
 
源代码2 项目: MeteoInfo   文件: JMonthChooser.java
/**
 * Initializes the locale specific month names.
 */
public void initNames() {
	localInitialize = true;

	DateFormatSymbols dateFormatSymbols = new DateFormatSymbols(locale);
	String[] monthNames = dateFormatSymbols.getMonths();

	if (comboBox.getItemCount() == 12) {
		comboBox.removeAllItems();
	}

	for (int i = 0; i < 12; i++) {
		comboBox.addItem(monthNames[i]);
	}

	localInitialize = false;
	comboBox.setSelectedIndex(month);
}
 
源代码3 项目: buffer_bci   文件: MonthDateFormat.java
/**
 * Creates a new formatter.
 *
 * @param zone  the time zone used to extract the month and year from dates
 *              passed to this formatter (<code>null</code> not permitted).
 * @param locale  the locale used to determine the month names
 *                (<code>null</code> not permitted).
 * @param chars  the maximum number of characters to use from the month
 *               names, or zero to indicate that the entire month name
 *               should be used.
 * @param showYear  an array of flags that control whether or not the
 *                  year is displayed for a particular month.
 * @param yearFormatter  the year formatter.
 */
public MonthDateFormat(TimeZone zone, Locale locale, int chars,
                       boolean[] showYear, DateFormat yearFormatter) {
    ParamChecks.nullNotPermitted(locale, "locale");
    DateFormatSymbols dfs = new DateFormatSymbols(locale);
    String[] monthsFromLocale = dfs.getMonths();
    this.months = new String[12];
    for (int i = 0; i < 12; i++) {
        if (chars > 0) {
            this.months[i] = monthsFromLocale[i].substring(0,
                    Math.min(chars, monthsFromLocale[i].length()));
        }
        else {
            this.months[i] = monthsFromLocale[i];
        }
    }
    this.calendar = new GregorianCalendar(zone);
    this.showYear = showYear;
    this.yearFormatter = yearFormatter;

    // the following is never used, but it seems that DateFormat requires
    // it to be non-null.  It isn't well covered in the spec, refer to
    // bug parade 5061189 for more info.
    this.numberFormat = NumberFormat.getNumberInstance();
}
 
源代码4 项目: ECG-Viewer   文件: MonthDateFormat.java
/**
 * Creates a new formatter.
 *
 * @param zone  the time zone used to extract the month and year from dates
 *              passed to this formatter (<code>null</code> not permitted).
 * @param locale  the locale used to determine the month names
 *                (<code>null</code> not permitted).
 * @param chars  the maximum number of characters to use from the month
 *               names, or zero to indicate that the entire month name
 *               should be used.
 * @param showYear  an array of flags that control whether or not the
 *                  year is displayed for a particular month.
 * @param yearFormatter  the year formatter.
 */
public MonthDateFormat(TimeZone zone, Locale locale, int chars,
                       boolean[] showYear, DateFormat yearFormatter) {
    ParamChecks.nullNotPermitted(locale, "locale");
    DateFormatSymbols dfs = new DateFormatSymbols(locale);
    String[] monthsFromLocale = dfs.getMonths();
    this.months = new String[12];
    for (int i = 0; i < 12; i++) {
        if (chars > 0) {
            this.months[i] = monthsFromLocale[i].substring(0,
                    Math.min(chars, monthsFromLocale[i].length()));
        }
        else {
            this.months[i] = monthsFromLocale[i];
        }
    }
    this.calendar = new GregorianCalendar(zone);
    this.showYear = showYear;
    this.yearFormatter = yearFormatter;

    // the following is never used, but it seems that DateFormat requires
    // it to be non-null.  It isn't well covered in the spec, refer to
    // bug parade 5061189 for more info.
    this.numberFormat = NumberFormat.getNumberInstance();
}
 
源代码5 项目: LGoodDatePicker   文件: ExtraDateStrings.java
/**
 * 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;
}
 
源代码6 项目: jdk1.8-source-analysis   文件: Calendar.java
private String[] getFieldStrings(int field, int style, DateFormatSymbols symbols) {
    int baseStyle = getBaseStyle(style); // ignore the standalone mask

    // DateFormatSymbols doesn't support any narrow names.
    if (baseStyle == NARROW_FORMAT) {
        return null;
    }

    String[] strings = null;
    switch (field) {
    case ERA:
        strings = symbols.getEras();
        break;

    case MONTH:
        strings = (baseStyle == LONG) ? symbols.getMonths() : symbols.getShortMonths();
        break;

    case DAY_OF_WEEK:
        strings = (baseStyle == LONG) ? symbols.getWeekdays() : symbols.getShortWeekdays();
        break;

    case AM_PM:
        strings = symbols.getAmPmStrings();
        break;
    }
    return strings;
}
 
源代码7 项目: web-data-extractor   文件: DateFormatSymbolsEx.java
public DateFormatSymbolsEx(Locale locale) {
    DateFormatSymbols dateFormatSymbols = new DateFormatSymbols(locale);

    months = dateFormatSymbols.getMonths();
    shortMonths = dateFormatSymbols.getShortMonths();
    weekdays = dateFormatSymbols.getWeekdays();
    shortWeekdays = dateFormatSymbols.getShortWeekdays();
    eras = dateFormatSymbols.getEras();
    ampms = dateFormatSymbols.getAmPmStrings();
}
 
源代码8 项目: TelePlus-Android   文件: FastDateParser.java
private static String[] getDisplayNameArray(int field, boolean isLong, Locale locale) {
    DateFormatSymbols dfs = new DateFormatSymbols(locale);
    switch (field) {
        case Calendar.AM_PM:
            return dfs.getAmPmStrings();
        case Calendar.DAY_OF_WEEK:
            return isLong ? dfs.getWeekdays() : dfs.getShortWeekdays();
        case Calendar.ERA:
            return dfs.getEras();
        case Calendar.MONTH:
            return isLong ? dfs.getMonths() : dfs.getShortMonths();
    }
    return null;
}
 
源代码9 项目: TencentKona-8   文件: Calendar.java
private String[] getFieldStrings(int field, int style, DateFormatSymbols symbols) {
    int baseStyle = getBaseStyle(style); // ignore the standalone mask

    // DateFormatSymbols doesn't support any narrow names.
    if (baseStyle == NARROW_FORMAT) {
        return null;
    }

    String[] strings = null;
    switch (field) {
    case ERA:
        strings = symbols.getEras();
        break;

    case MONTH:
        strings = (baseStyle == LONG) ? symbols.getMonths() : symbols.getShortMonths();
        break;

    case DAY_OF_WEEK:
        strings = (baseStyle == LONG) ? symbols.getWeekdays() : symbols.getShortWeekdays();
        break;

    case AM_PM:
        strings = symbols.getAmPmStrings();
        break;
    }
    return strings;
}
 
源代码10 项目: opensim-gui   文件: MonthDateFormat.java
/**
 * Creates a new formatter.
 * 
 * @param zone  the time zone used to extract the month and year from dates
 *              passed to this formatter (<code>null</code> not permitted).
 * @param locale  the locale used to determine the month names 
 *                (<code>null</code> not permitted).
 * @param chars  the maximum number of characters to use from the month 
 *               names, or zero to indicate that the entire month name 
 *               should be used.
 * @param showYear  an array of flags that control whether or not the
 *                  year is displayed for a particular month.
 * @param yearFormatter  the year formatter.
 */
public MonthDateFormat(TimeZone zone, Locale locale, int chars, 
                       boolean[] showYear, DateFormat yearFormatter) {
    if (locale == null) {
        throw new IllegalArgumentException("Null 'locale' argument.");
    }
    DateFormatSymbols dfs = new DateFormatSymbols(locale);
    String[] monthsFromLocale = dfs.getMonths();
    this.months = new String[12];
    for (int i = 0; i < 12; i++) {
        if (chars > 0) {
            months[i] = monthsFromLocale[i].substring(0, 
                    Math.min(chars, monthsFromLocale[i].length()));
        }
        else {
            months[i] = monthsFromLocale[i];
        }
    }
    this.calendar = new GregorianCalendar(zone);
    this.showYear = showYear;
    this.yearFormatter = yearFormatter; 
    
    // the following is never used, but it seems that DateFormat requires
    // it to be non-null.  It isn't well covered in the spec, refer to 
    // bug parade 5061189 for more info.
    this.numberFormat = NumberFormat.getNumberInstance();
}
 
源代码11 项目: common-utils   文件: LocaledDateFormat.java
public LocaledDateFormat(Locale locale) {
    DateFormatSymbols dateFormatSymbols = new DateFormatSymbols(locale);

    months = dateFormatSymbols.getMonths();
    shortMonths = dateFormatSymbols.getShortMonths();
    weekdays = dateFormatSymbols.getWeekdays();
    shortWeekdays = dateFormatSymbols.getShortWeekdays();
    eras = dateFormatSymbols.getEras();
    ampms = dateFormatSymbols.getAmPmStrings();
}
 
源代码12 项目: nebula   文件: DateHelper.java
/**
 * Parses a string (representing a month) and returns it's corresponding
 * value as a Calendar month. This is used to parse MMM month dates
 * 
 * @param monthStr
 *            String to parse
 * @param locale
 *            Locale to use
 * @return Month value or -1 if not found
 */
private static int getMonthForString(String monthStr, Locale locale) {
	DateFormatSymbols dfs = new DateFormatSymbols(locale);
	String[] months = dfs.getMonths();
	for (int i = 0; i < months.length; i++) {
		if (months[i].toLowerCase(locale).startsWith(monthStr.toLowerCase(locale))) {
			return i + 1;
		}
	}

	return -1;
}
 
源代码13 项目: jdk8u-jdk   文件: Calendar.java
private String[] getFieldStrings(int field, int style, DateFormatSymbols symbols) {
    int baseStyle = getBaseStyle(style); // ignore the standalone mask

    // DateFormatSymbols doesn't support any narrow names.
    if (baseStyle == NARROW_FORMAT) {
        return null;
    }

    String[] strings = null;
    switch (field) {
    case ERA:
        strings = symbols.getEras();
        break;

    case MONTH:
        strings = (baseStyle == LONG) ? symbols.getMonths() : symbols.getShortMonths();
        break;

    case DAY_OF_WEEK:
        strings = (baseStyle == LONG) ? symbols.getWeekdays() : symbols.getShortWeekdays();
        break;

    case AM_PM:
        strings = symbols.getAmPmStrings();
        break;
    }
    return strings;
}
 
源代码14 项目: openjdk-jdk8u   文件: Calendar.java
private String[] getFieldStrings(int field, int style, DateFormatSymbols symbols) {
    int baseStyle = getBaseStyle(style); // ignore the standalone mask

    // DateFormatSymbols doesn't support any narrow names.
    if (baseStyle == NARROW_FORMAT) {
        return null;
    }

    String[] strings = null;
    switch (field) {
    case ERA:
        strings = symbols.getEras();
        break;

    case MONTH:
        strings = (baseStyle == LONG) ? symbols.getMonths() : symbols.getShortMonths();
        break;

    case DAY_OF_WEEK:
        strings = (baseStyle == LONG) ? symbols.getWeekdays() : symbols.getShortWeekdays();
        break;

    case AM_PM:
        strings = symbols.getAmPmStrings();
        break;
    }
    return strings;
}
 
源代码15 项目: openjdk-jdk8u-backup   文件: Calendar.java
private String[] getFieldStrings(int field, int style, DateFormatSymbols symbols) {
    int baseStyle = getBaseStyle(style); // ignore the standalone mask

    // DateFormatSymbols doesn't support any narrow names.
    if (baseStyle == NARROW_FORMAT) {
        return null;
    }

    String[] strings = null;
    switch (field) {
    case ERA:
        strings = symbols.getEras();
        break;

    case MONTH:
        strings = (baseStyle == LONG) ? symbols.getMonths() : symbols.getShortMonths();
        break;

    case DAY_OF_WEEK:
        strings = (baseStyle == LONG) ? symbols.getWeekdays() : symbols.getShortWeekdays();
        break;

    case AM_PM:
        strings = symbols.getAmPmStrings();
        break;
    }
    return strings;
}
 
源代码16 项目: Bytecoder   文件: Calendar.java
private String[] getFieldStrings(int field, int style, DateFormatSymbols symbols) {
    int baseStyle = getBaseStyle(style); // ignore the standalone mask

    // DateFormatSymbols doesn't support any narrow names.
    if (baseStyle == NARROW_FORMAT) {
        return null;
    }

    String[] strings = null;
    switch (field) {
    case ERA:
        strings = symbols.getEras();
        break;

    case MONTH:
        strings = (baseStyle == LONG) ? symbols.getMonths() : symbols.getShortMonths();
        break;

    case DAY_OF_WEEK:
        strings = (baseStyle == LONG) ? symbols.getWeekdays() : symbols.getShortWeekdays();
        break;

    case AM_PM:
        strings = symbols.getAmPmStrings();
        break;
    }
    return strings;
}
 
源代码17 项目: LGoodDatePicker   文件: CalendarPanel.java
/**
 * 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();
}
 
源代码18 项目: Java8CN   文件: Calendar.java
private String[] getFieldStrings(int field, int style, DateFormatSymbols symbols) {
    int baseStyle = getBaseStyle(style); // ignore the standalone mask

    // DateFormatSymbols doesn't support any narrow names.
    if (baseStyle == NARROW_FORMAT) {
        return null;
    }

    String[] strings = null;
    switch (field) {
    case ERA:
        strings = symbols.getEras();
        break;

    case MONTH:
        strings = (baseStyle == LONG) ? symbols.getMonths() : symbols.getShortMonths();
        break;

    case DAY_OF_WEEK:
        strings = (baseStyle == LONG) ? symbols.getWeekdays() : symbols.getShortWeekdays();
        break;

    case AM_PM:
        strings = symbols.getAmPmStrings();
        break;
    }
    return strings;
}
 
源代码19 项目: hottub   文件: Calendar.java
private String[] getFieldStrings(int field, int style, DateFormatSymbols symbols) {
    int baseStyle = getBaseStyle(style); // ignore the standalone mask

    // DateFormatSymbols doesn't support any narrow names.
    if (baseStyle == NARROW_FORMAT) {
        return null;
    }

    String[] strings = null;
    switch (field) {
    case ERA:
        strings = symbols.getEras();
        break;

    case MONTH:
        strings = (baseStyle == LONG) ? symbols.getMonths() : symbols.getShortMonths();
        break;

    case DAY_OF_WEEK:
        strings = (baseStyle == LONG) ? symbols.getWeekdays() : symbols.getShortWeekdays();
        break;

    case AM_PM:
        strings = symbols.getAmPmStrings();
        break;
    }
    return strings;
}
 
源代码20 项目: openbd-core   文件: monthConverter.java
public static int convertMonthToInt(char month[], DateFormatSymbols _dfs){
  String months[] = _dfs.getMonths();
  String shortmonths[] = _dfs.getShortMonths();
        
  for(int i = 0; i < months.length; i++)
    if(equal(month, months[i]) || equal(month, shortmonths[i]))
      return i;

  return -1;
}