List of usage examples for java.text DateFormatSymbols getShortMonths
public String[] getShortMonths()
From source file:Main.java
public static String getSubNameOFMonth(int month) { DateFormatSymbols dateFormatSymbol = new DateFormatSymbols(); String monthName = dateFormatSymbol.getShortMonths()[month]; return monthName; }
From source file:de.undercouch.citeproc.bibtex.DateParser.java
/** * Retrieves and caches a list of month names for a given locale * @param locale the locale// ww w.ja v a 2 s . c o m * @return the list of month names (short and long). All names are * converted to upper case */ private static Map<String, Integer> getMonthNames(Locale locale) { Map<String, Integer> r = MONTH_NAMES_CACHE.get(locale); if (r == null) { DateFormatSymbols symbols = DateFormatSymbols.getInstance(locale); r = new HashMap<String, Integer>(24); //insert long month names String[] months = symbols.getMonths(); for (int i = 0; i < months.length; ++i) { String m = months[i]; if (!m.isEmpty()) { r.put(m.toUpperCase(), i + 1); } } //insert short month names String[] shortMonths = symbols.getShortMonths(); for (int i = 0; i < shortMonths.length; ++i) { String m = shortMonths[i]; if (!m.isEmpty()) { r.put(m.toUpperCase(), i + 1); } } MONTH_NAMES_CACHE.put(locale, r); } return r; }
From source file:com.cognizant.trumobi.em.Email.java
public static String getNameOFMonth(int month) { // int month = 3; // Calendar cal = Calendar.getInstance(); DateFormatSymbols dateFormatSymbol = new DateFormatSymbols(); String monthName = dateFormatSymbol.getShortMonths()[month - 1]; return monthName; }
From source file:com.qtplaf.library.util.Calendar.java
/** * Returns an array of localized names of months. * * @return An array of names./*from w w w.j a v a 2 s.co m*/ * @param locale The desired locale. * @param capitalized A boolean to capitalize the name. */ public static String[] getShortMonths(Locale locale, boolean capitalized) { DateFormatSymbols sysd = new DateFormatSymbols(locale); String[] dsc = sysd.getShortMonths(); if (capitalized) { for (int i = 0; i < dsc.length; i++) { dsc[i] = StringUtils.capitalize(dsc[i]); } } return dsc; }
From source file:com.application.utils.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(); }// w w w.j av a 2 s .c o m return null; }
From source file:org.apache.myfaces.custom.calendar.HtmlCalendarRenderer.java
public static String[] mapShortMonths(DateFormatSymbols symbols) { String[] months = new String[12]; String[] localeMonths = symbols.getShortMonths(); months[0] = localeMonths[Calendar.JANUARY]; months[1] = localeMonths[Calendar.FEBRUARY]; months[2] = localeMonths[Calendar.MARCH]; months[3] = localeMonths[Calendar.APRIL]; months[4] = localeMonths[Calendar.MAY]; months[5] = localeMonths[Calendar.JUNE]; months[6] = localeMonths[Calendar.JULY]; months[7] = localeMonths[Calendar.AUGUST]; months[8] = localeMonths[Calendar.SEPTEMBER]; months[9] = localeMonths[Calendar.OCTOBER]; months[10] = localeMonths[Calendar.NOVEMBER]; months[11] = localeMonths[Calendar.DECEMBER]; return months; }
From source file:org.apache.click.extras.control.DateField.java
/** * Return the names of months and weekdays as a script. */// w w w.j a va 2 s . co m protected void addCalenderTranslations(List<Element> headElements) { JsScript script = new JsScript(); script.setId("datefield-js-setup-global"); if (!headElements.contains(script)) { DateFormatSymbols dfs = new DateFormatSymbols(getLocale()); HtmlStringBuffer buffer = new HtmlStringBuffer(150); buffer.append("Date.months=new Array("); generateJavaScriptArray(buffer, dfs.getMonths(), 0, 12); buffer.append(");\n"); buffer.append("Date.monthAbbreviations=new Array("); generateJavaScriptArray(buffer, dfs.getShortMonths(), 0, 12); buffer.append(");\n"); buffer.append("Date.dayNames=new Array("); generateJavaScriptArray(buffer, dfs.getWeekdays(), Calendar.SUNDAY, Calendar.SATURDAY + 1); buffer.append(");\n"); buffer.append("Date.dayAbbreviations=new Array("); generateJavaScriptArray(buffer, dfs.getShortWeekdays(), Calendar.SUNDAY, Calendar.SATURDAY + 1); buffer.append(");\n"); String[] weekdays = null; if (getMessages().containsKey("calendar-weekdays-heading")) { String headings = getMessage("calendar-weekdays-heading"); weekdays = StringUtils.splitPreserveAllTokens("," + headings, ','); } else { weekdays = dfs.getShortWeekdays(); } String[] days = new String[7]; int firstDayOfWeek = getFirstDayOfWeek() - 1; for (int i = 0; i < 7; i++) { days[i] = weekdays[(i + firstDayOfWeek) % 7 + 1]; } buffer.append("Date.weekdays=new Array("); generateJavaScriptArray(buffer, days, 0, 7); buffer.append(");\n"); buffer.append("Date.first_day_of_week=").append(firstDayOfWeek).append(";\n"); if (getMessages().containsKey("calendar-ok")) { buffer.append("_translations[\"OK\"] = \""); buffer.append(getMessage("calendar-ok")); buffer.append("\";\n"); } if (getMessages().containsKey("calendar-now")) { buffer.append("_translations[\"Now\"] = \""); buffer.append(getMessage("calendar-now")); buffer.append("\";\n"); } if (getMessages().containsKey("calendar-today")) { buffer.append("_translations[\"Today\"] = \""); buffer.append(getMessage("calendar-today")); buffer.append("\";\n"); } if (getMessages().containsKey("calendar-clear")) { buffer.append("_translations[\"Clear\"] = \""); buffer.append(getMessage("calendar-clear")); buffer.append("\";\n"); } script.setContent(buffer.toString()); headElements.add(script); } }
From source file:com.application.utils.FastDatePrinter.java
/** * <p>Returns a list of Rules given a pattern.</p> * * @return a {@code List} of Rule objects * @throws IllegalArgumentException if pattern is invalid *///from w w w .j a v a2 s . c om protected List<Rule> parsePattern() { final DateFormatSymbols symbols = new DateFormatSymbols(mLocale); final List<Rule> rules = new ArrayList<Rule>(); final String[] ERAs = symbols.getEras(); final String[] months = symbols.getMonths(); final String[] shortMonths = symbols.getShortMonths(); final String[] weekdays = symbols.getWeekdays(); final String[] shortWeekdays = symbols.getShortWeekdays(); final String[] AmPmStrings = symbols.getAmPmStrings(); final int length = mPattern.length(); final int[] indexRef = new int[1]; for (int i = 0; i < length; i++) { indexRef[0] = i; final String token = parseToken(mPattern, indexRef); i = indexRef[0]; final int tokenLen = token.length(); if (tokenLen == 0) { break; } Rule rule; final char c = token.charAt(0); switch (c) { case 'G': // era designator (text) rule = new TextField(Calendar.ERA, ERAs); break; case 'y': // year (number) if (tokenLen == 2) { rule = TwoDigitYearField.INSTANCE; } else { rule = selectNumberRule(Calendar.YEAR, tokenLen < 4 ? 4 : tokenLen); } break; case 'M': // month in year (text and number) if (tokenLen >= 4) { rule = new TextField(Calendar.MONTH, months); } else if (tokenLen == 3) { rule = new TextField(Calendar.MONTH, shortMonths); } else if (tokenLen == 2) { rule = TwoDigitMonthField.INSTANCE; } else { rule = UnpaddedMonthField.INSTANCE; } break; case 'd': // day in month (number) rule = selectNumberRule(Calendar.DAY_OF_MONTH, tokenLen); break; case 'h': // hour in am/pm (number, 1..12) rule = new TwelveHourField(selectNumberRule(Calendar.HOUR, tokenLen)); break; case 'H': // hour in day (number, 0..23) rule = selectNumberRule(Calendar.HOUR_OF_DAY, tokenLen); break; case 'm': // minute in hour (number) rule = selectNumberRule(Calendar.MINUTE, tokenLen); break; case 's': // second in minute (number) rule = selectNumberRule(Calendar.SECOND, tokenLen); break; case 'S': // millisecond (number) rule = selectNumberRule(Calendar.MILLISECOND, tokenLen); break; case 'E': // day in week (text) rule = new TextField(Calendar.DAY_OF_WEEK, tokenLen < 4 ? shortWeekdays : weekdays); break; case 'D': // day in year (number) rule = selectNumberRule(Calendar.DAY_OF_YEAR, tokenLen); break; case 'F': // day of week in month (number) rule = selectNumberRule(Calendar.DAY_OF_WEEK_IN_MONTH, tokenLen); break; case 'w': // week in year (number) rule = selectNumberRule(Calendar.WEEK_OF_YEAR, tokenLen); break; case 'W': // week in month (number) rule = selectNumberRule(Calendar.WEEK_OF_MONTH, tokenLen); break; case 'a': // am/pm marker (text) rule = new TextField(Calendar.AM_PM, AmPmStrings); break; case 'k': // hour in day (1..24) rule = new TwentyFourHourField(selectNumberRule(Calendar.HOUR_OF_DAY, tokenLen)); break; case 'K': // hour in am/pm (0..11) rule = selectNumberRule(Calendar.HOUR, tokenLen); break; case 'z': // time zone (text) if (tokenLen >= 4) { rule = new TimeZoneNameRule(mTimeZone, mLocale, TimeZone.LONG); } else { rule = new TimeZoneNameRule(mTimeZone, mLocale, TimeZone.SHORT); } break; case 'Z': // time zone (value) if (tokenLen == 1) { rule = TimeZoneNumberRule.INSTANCE_NO_COLON; } else { rule = TimeZoneNumberRule.INSTANCE_COLON; } break; case '\'': // literal text final String sub = token.substring(1); if (sub.length() == 1) { rule = new CharacterLiteral(sub.charAt(0)); } else { rule = new StringLiteral(sub); } break; default: throw new IllegalArgumentException("Illegal pattern component: " + token); } rules.add(rule); } return rules; }
From source file:org.sqlite.date.FastDatePrinter.java
/** * <p>Returns a list of Rules given a pattern.</p> * * @return a {@code List} of Rule objects * @throws IllegalArgumentException if pattern is invalid *///from w ww . j ava2 s . com protected List<Rule> parsePattern() { final DateFormatSymbols symbols = new DateFormatSymbols(mLocale); final List<Rule> rules = new ArrayList<Rule>(); final String[] ERAs = symbols.getEras(); final String[] months = symbols.getMonths(); final String[] shortMonths = symbols.getShortMonths(); final String[] weekdays = symbols.getWeekdays(); final String[] shortWeekdays = symbols.getShortWeekdays(); final String[] AmPmStrings = symbols.getAmPmStrings(); final int length = mPattern.length(); final int[] indexRef = new int[1]; for (int i = 0; i < length; i++) { indexRef[0] = i; final String token = parseToken(mPattern, indexRef); i = indexRef[0]; final int tokenLen = token.length(); if (tokenLen == 0) { break; } Rule rule; final char c = token.charAt(0); switch (c) { case 'G': // era designator (text) rule = new TextField(Calendar.ERA, ERAs); break; case 'y': // year (number) if (tokenLen == 2) { rule = TwoDigitYearField.INSTANCE; } else { rule = selectNumberRule(Calendar.YEAR, tokenLen < 4 ? 4 : tokenLen); } break; case 'M': // month in year (text and number) if (tokenLen >= 4) { rule = new TextField(Calendar.MONTH, months); } else if (tokenLen == 3) { rule = new TextField(Calendar.MONTH, shortMonths); } else if (tokenLen == 2) { rule = TwoDigitMonthField.INSTANCE; } else { rule = UnpaddedMonthField.INSTANCE; } break; case 'd': // day in month (number) rule = selectNumberRule(Calendar.DAY_OF_MONTH, tokenLen); break; case 'h': // hour in am/pm (number, 1..12) rule = new TwelveHourField(selectNumberRule(Calendar.HOUR, tokenLen)); break; case 'H': // hour in day (number, 0..23) rule = selectNumberRule(Calendar.HOUR_OF_DAY, tokenLen); break; case 'm': // minute in hour (number) rule = selectNumberRule(Calendar.MINUTE, tokenLen); break; case 's': // second in minute (number) rule = selectNumberRule(Calendar.SECOND, tokenLen); break; case 'S': // millisecond (number) rule = selectNumberRule(Calendar.MILLISECOND, tokenLen); break; case 'E': // day in week (text) rule = new TextField(Calendar.DAY_OF_WEEK, tokenLen < 4 ? shortWeekdays : weekdays); break; case 'D': // day in year (number) rule = selectNumberRule(Calendar.DAY_OF_YEAR, tokenLen); break; case 'F': // day of week in month (number) rule = selectNumberRule(Calendar.DAY_OF_WEEK_IN_MONTH, tokenLen); break; case 'w': // week in year (number) rule = selectNumberRule(Calendar.WEEK_OF_YEAR, tokenLen); break; case 'W': // week in month (number) rule = selectNumberRule(Calendar.WEEK_OF_MONTH, tokenLen); break; case 'a': // am/pm marker (text) rule = new TextField(Calendar.AM_PM, AmPmStrings); break; case 'k': // hour in day (1..24) rule = new TwentyFourHourField(selectNumberRule(Calendar.HOUR_OF_DAY, tokenLen)); break; case 'K': // hour in am/pm (0..11) rule = selectNumberRule(Calendar.HOUR, tokenLen); break; case 'X': // ISO 8601 rule = Iso8601_Rule.getRule(tokenLen); break; case 'z': // time zone (text) if (tokenLen >= 4) { rule = new TimeZoneNameRule(mTimeZone, mLocale, TimeZone.LONG); } else { rule = new TimeZoneNameRule(mTimeZone, mLocale, TimeZone.SHORT); } break; case 'Z': // time zone (value) if (tokenLen == 1) { rule = TimeZoneNumberRule.INSTANCE_NO_COLON; } else if (tokenLen == 2) { rule = TimeZoneNumberRule.INSTANCE_ISO_8601; } else { rule = TimeZoneNumberRule.INSTANCE_COLON; } break; case '\'': // literal text final String sub = token.substring(1); if (sub.length() == 1) { rule = new CharacterLiteral(sub.charAt(0)); } else { rule = new StringLiteral(sub); } break; default: throw new IllegalArgumentException("Illegal pattern component: " + token); } rules.add(rule); } return rules; }
From source file:org.richfaces.renderkit.CalendarRendererBase.java
protected Map<String, String[]> getSymbolsMap(FacesContext facesContext, UICalendar calendar) { Map<String, String[]> map = new HashMap<String, String[]>(); Locale locale = calendar.getAsLocale(calendar.getLocale()); Calendar cal = calendar.getCalendar(); int maximum = cal.getActualMaximum(Calendar.DAY_OF_WEEK); int minimum = cal.getActualMinimum(Calendar.DAY_OF_WEEK); int monthMax = cal.getActualMaximum(Calendar.MONTH); int monthMin = cal.getActualMinimum(Calendar.MONTH); DateFormatSymbols symbols = new DateFormatSymbols(locale); String[] weekDayLabels = ComponentUtil.asArray(calendar.getWeekDayLabels()); if (weekDayLabels == null) { weekDayLabels = symbols.getWeekdays(); weekDayLabels = shiftDates(minimum, maximum, weekDayLabels); }/* w w w . ja v a2 s .c om*/ String[] weekDayLabelsShort = ComponentUtil.asArray(calendar.getWeekDayLabelsShort()); if (weekDayLabelsShort == null) { weekDayLabelsShort = symbols.getShortWeekdays(); weekDayLabelsShort = shiftDates(minimum, maximum, weekDayLabelsShort); } String[] monthLabels = ComponentUtil.asArray(calendar.getMonthLabels()); if (monthLabels == null) { monthLabels = symbols.getMonths(); monthLabels = shiftDates(monthMin, monthMax, monthLabels); } String[] monthLabelsShort = ComponentUtil.asArray(calendar.getMonthLabelsShort()); if (monthLabelsShort == null) { monthLabelsShort = symbols.getShortMonths(); monthLabelsShort = shiftDates(monthMin, monthMax, monthLabelsShort); } map.put(WEEK_DAY_LABELS, weekDayLabels); map.put(WEEK_DAY_LABELS_SHORT, weekDayLabelsShort); map.put(MONTH_LABELS, monthLabels); map.put(MONTH_LABELS_SHORT, monthLabelsShort); return map; }