Java Code Examples for java.text.DateFormatSymbols#getMonths()

The following examples show how to use java.text.DateFormatSymbols#getMonths() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExtraDateStrings.java    From LGoodDatePicker with MIT License 6 votes vote down vote up
/**
 * 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;
}
 
Example 2
Source File: MonthDateFormat.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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();
}
 
Example 3
Source File: MonthDateFormat.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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();
}
 
Example 4
Source File: Calendar.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example 5
Source File: monthConverter.java    From openbd-core with GNU General Public License v3.0 5 votes vote down vote up
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;
}
 
Example 6
Source File: Calendar.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example 7
Source File: Calendar.java    From Java8CN with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 8
Source File: CalendarPanel.java    From LGoodDatePicker with MIT License 5 votes vote down vote up
/**
 * 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();
}
 
Example 9
Source File: MonthDateFormat.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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();
}
 
Example 10
Source File: Calendar.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 11
Source File: Calendar.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example 12
Source File: Calendar.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example 13
Source File: DateHelper.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 14
Source File: LocaledDateFormat.java    From common-utils with GNU General Public License v2.0 5 votes vote down vote up
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();
}
 
Example 15
Source File: MonthDateFormat.java    From opensim-gui with Apache License 2.0 5 votes vote down vote up
/**
 * 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();
}
 
Example 16
Source File: Calendar.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example 17
Source File: FastDateParser.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example 18
Source File: DateFormatSymbolsEx.java    From web-data-extractor with Apache License 2.0 5 votes vote down vote up
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();
}
 
Example 19
Source File: JMonthChooser.java    From MeteoInfo with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 20
Source File: Calendar.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
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;
}