List of usage examples for java.text DateFormatSymbols DateFormatSymbols
private DateFormatSymbols(boolean flag)
From source file:Main.java
/** * Convert 2 to February/*from w w w . ja va 2s. co m*/ * * @param month * @param locale * @return */ public static String formatMonth(int month, Locale locale) { DateFormatSymbols symbols = new DateFormatSymbols(locale); String[] monthNames = symbols.getMonths(); return monthNames[month - 1]; }
From source file:DateFormatSymbolsDemo.java
static public void changeWeekDays() { Date today;//from w w w . j av a 2 s.c om String result; SimpleDateFormat formatter; DateFormatSymbols symbols; String[] defaultDays; String[] modifiedDays; symbols = new DateFormatSymbols(new Locale("en", "US")); defaultDays = symbols.getShortWeekdays(); for (int i = 0; i < defaultDays.length; i++) { System.out.print(defaultDays[i] + " "); } System.out.println(); String[] capitalDays = { "", "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT" }; symbols.setShortWeekdays(capitalDays); modifiedDays = symbols.getShortWeekdays(); for (int i = 0; i < modifiedDays.length; i++) { System.out.print(modifiedDays[i] + " "); } System.out.println(); System.out.println(); formatter = new SimpleDateFormat("E", symbols); today = new Date(); result = formatter.format(today); System.out.println(result); }
From source file:com.inkubator.hrm.web.converter.MonthNumberAsStringConverter.java
@Override public String getAsString(FacesContext context, UIComponent component, Object value) { String monthAsString = StringUtils.EMPTY; String data = value.toString(); if (StringUtils.isNumeric(data)) { Integer month = Integer.valueOf(data); DateFormatSymbols dfs = new DateFormatSymbols( new Locale(FacesUtil.getSessionAttribute(HRMConstant.BAHASA_ACTIVE).toString())); monthAsString = dfs.getMonths()[month - 1]; }/*ww w .jav a2 s . c om*/ return monthAsString; }
From source file:JapaneseCalendar.java
public void paintComponent(Graphics g) { int width = 400; int height = 400; Calendar cal = Calendar.getInstance(locale); cal.setTime(new Date()); String header = cal.getDisplayName(Calendar.MONTH, Calendar.LONG, locale); header += " " + cal.get(Calendar.YEAR); FontMetrics fm = g.getFontMetrics(); Insets insets = getInsets();//from ww w . ja va 2 s. c o m g.setColor(Color.black); g.drawString(header, (width - fm.stringWidth(header)) / 2, insets.top + fm.getHeight()); DateFormatSymbols dfs = new DateFormatSymbols(locale); String[] weekdayNames = dfs.getShortWeekdays(); int fieldWidth = (width - insets.left - insets.right) / 7; g.drawString(weekdayNames[Calendar.SUNDAY], insets.left + (fieldWidth - fm.stringWidth(weekdayNames[Calendar.SUNDAY])) / 2, insets.top + 3 * fm.getHeight()); g.drawString(weekdayNames[Calendar.MONDAY], insets.left + fieldWidth + (fieldWidth - fm.stringWidth(weekdayNames[Calendar.MONDAY])) / 2, insets.top + 3 * fm.getHeight()); g.drawString(weekdayNames[Calendar.TUESDAY], insets.left + 2 * fieldWidth + (fieldWidth - fm.stringWidth(weekdayNames[Calendar.TUESDAY])) / 2, insets.top + 3 * fm.getHeight()); g.drawString(weekdayNames[Calendar.WEDNESDAY], insets.left + 3 * fieldWidth + (fieldWidth - fm.stringWidth(weekdayNames[Calendar.WEDNESDAY])) / 2, insets.top + 3 * fm.getHeight()); g.drawString(weekdayNames[Calendar.THURSDAY], insets.left + 4 * fieldWidth + (fieldWidth - fm.stringWidth(weekdayNames[Calendar.THURSDAY])) / 2, insets.top + 3 * fm.getHeight()); g.drawString(weekdayNames[Calendar.FRIDAY], insets.left + 5 * fieldWidth + (fieldWidth - fm.stringWidth(weekdayNames[Calendar.FRIDAY])) / 2, insets.top + 3 * fm.getHeight()); g.drawString(weekdayNames[Calendar.SATURDAY], insets.left + 6 * fieldWidth + (fieldWidth - fm.stringWidth(weekdayNames[Calendar.SATURDAY])) / 2, insets.top + 3 * fm.getHeight()); int dom = cal.get(Calendar.DAY_OF_MONTH); cal.set(Calendar.DAY_OF_MONTH, 1); int col = 0; switch (cal.get(Calendar.DAY_OF_WEEK)) { case Calendar.MONDAY: col = 1; break; case Calendar.TUESDAY: col = 2; break; case Calendar.WEDNESDAY: col = 3; break; case Calendar.THURSDAY: col = 4; break; case Calendar.FRIDAY: col = 5; break; case Calendar.SATURDAY: col = 6; } cal.set(Calendar.DAY_OF_MONTH, dom); int row = 5 * fm.getHeight(); for (int i = 1; i <= cal.getActualMaximum(Calendar.DAY_OF_MONTH); i++) { g.drawString("" + i, insets.left + fieldWidth * col + (fieldWidth - fm.stringWidth("" + i)) / 2, row); if (++col > 6) { col = 0; row += fm.getHeight(); } } }
From source file:it.andreale.mdatetimepicker.date.MonthAdapter.java
public MonthAdapter(AdapterController controller) { mController = controller; months = new DateFormatSymbols(Locale.getDefault()).getMonths(); }
From source file:org.alfresco.service.cmr.calendar.CalendarRecurrenceHelper.java
/** * Returns a lookup from recurrence rule days of the week, to * the proper days of the week in the specified locale *///from w ww .jav a 2s .c o m public static Map<String, String> buildLocalRecurrenceDaysOfTheWeek(Locale locale) { // Get our days of the week, in the current locale DateFormatSymbols dates = new DateFormatSymbols(I18NUtil.getLocale()); String[] weekdays = dates.getWeekdays(); // And map them based on the outlook two letter codes Map<String, String> days = new HashMap<String, String>(); for (Map.Entry<String, Integer> e : DAY_NAMES_TO_CALENDAR_DAYS.entrySet()) { days.put(e.getKey(), weekdays[e.getValue()]); } return days; }
From source file:com.googlecode.commons.swing.component.datetime.MiniDateCalendar.java
private void init() { final DateFormatSymbols dfs = new DateFormatSymbols(locale); CollectionUtils.addAll(this.weekdays, dfs.getShortWeekdays()); for (int i = 0; i < 7; i++) { orderedWeekdays.add(((i + weekDayStart - 1) % 7) + 1); }// www .j a v a 2s . c om setLayout(new BorderLayout()); SizeUtils.setAllWidths(this, 150); SizeUtils.setAllHeights(this, 180); panNorth = new JPanel(new BorderLayout()); add(panNorth, BorderLayout.NORTH); btnPrev = new JButton(); SizeUtils.setAllWidths(btnPrev, 18); SizeUtils.setAllHeights(btnPrev, 18); btnPrev.setIcon(DefaultIcons.resultset_previous()); btnPrev.setMargin(new Insets(0, 0, 0, 0)); btnPrev.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { onClickPrev(); } }); panNorth.add(btnPrev, BorderLayout.WEST); lblMonth = new JLabel(); SizeUtils.setMinHeight(lblMonth, 0); SizeUtils.setPreferredHeight(lblMonth, 0); lblMonth.setHorizontalAlignment(SwingConstants.CENTER); panNorth.add(lblMonth, BorderLayout.CENTER); btnNext = new JButton(); btnNext.setIcon(DefaultIcons.resultset_next()); SizeUtils.setAllWidths(btnNext, 18); SizeUtils.setAllHeights(btnNext, 18); btnNext.setMargin(new Insets(0, 0, 0, 0)); btnNext.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { onClickNext(); } }); panNorth.add(btnNext, BorderLayout.EAST); panCenter = new JPanel(); panCenter.setLayout(new GridLayout(7, 7)); add(panCenter, BorderLayout.CENTER); for (int col = 0; col < 7; col++) { JLabel lblDay = new JLabel(weekdays.get(orderedWeekdays.get(col))); lblDay.setHorizontalAlignment(SwingConstants.CENTER); panCenter.add(lblDay); } ButtonGroup grp = new ButtonGroup(); for (int row = 0; row < 6; row++) { for (int col = 0; col < 7; col++) { final int day = orderedWeekdays.get(col); final DayButton btn = createDayButton(day, weekdays.get(day)); btn.setMargin(new Insets(0, 0, 0, 0)); btn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { onClickDay(btn.value); } }); days.add(btn); grp.add(btn); panCenter.add(btn); } } refresh(); }
From source file:de.hybris.platform.commercefacades.storelocator.converters.populator.OpeningDayPopulator.java
/** * Assumption order is not a locale related ,removes an empty entries * /*from www . java2s . c o m*/ **/ protected List<String> getWeekDaySymbols() { final List<String> notEmptyWeekDay = new ArrayList<String>(); final DateFormatSymbols weekDaySymbols = new DateFormatSymbols(getCurrentLocale()); for (final String anyWeekDay : weekDaySymbols.getShortWeekdays()) { if (StringUtils.isNotBlank(anyWeekDay)) { notEmptyWeekDay.add(anyWeekDay); } } return notEmptyWeekDay; }
From source file:com.autentia.jsf.component.ocupation.HtmlOcupationCalendarRenderer.java
@Override public void encodeEnd(FacesContext facesContext, UIComponent component) throws IOException { log.debug("encodeEnd - component=\"" + component + "\"."); RendererUtils.checkParamValidity(facesContext, component, HtmlOcupationCalendar.class); HtmlOcupationCalendar inputCalendar = (HtmlOcupationCalendar) component; Locale currentLocale = facesContext.getViewRoot().getLocale(); Date value = null;/*from w ww . ja va2s . c om*/ Calendar timeKeeper = Calendar.getInstance(currentLocale); timeKeeper.setTime(new Date()); try { value = new CalendarDateTimeConverter().getAsDate(facesContext, inputCalendar); timeKeeper.setTime(value); } catch (IllegalArgumentException i) { log.warn("encodeEnd - IllegalArgumentException", i); } if (log.isDebugEnabled()) { log.debug("encodeEnd - timeKeeper=\"" + timeKeeper.getTime() + "\"."); } DateFormatSymbols symbols = new DateFormatSymbols(currentLocale); String[] weekdays = mapShortWeekdays(symbols); int lastDayInMonth = timeKeeper.getActualMaximum(Calendar.DAY_OF_MONTH); int currentDay = timeKeeper.get(Calendar.DAY_OF_MONTH); if (currentDay > lastDayInMonth) currentDay = lastDayInMonth; timeKeeper.set(Calendar.DAY_OF_MONTH, 1); int weekDayOfFirstDayOfMonth = mapCalendarDayToCommonDay(timeKeeper.get(Calendar.DAY_OF_WEEK)); int weekStartsAtDayIndex = mapCalendarDayToCommonDay(timeKeeper.getFirstDayOfWeek()); ResponseWriter writer = facesContext.getResponseWriter(); HtmlRendererUtils.writePrettyLineSeparator(facesContext); HtmlRendererUtils.writePrettyLineSeparator(facesContext); // render table writer.startElement(HTML.TABLE_ELEM, component); HtmlRendererUtils.renderHTMLAttributes(writer, component, HTML.UNIVERSAL_ATTRIBUTES); HtmlRendererUtils.renderHTMLAttributes(writer, component, HTML.EVENT_HANDLER_ATTRIBUTES); writer.flush(); HtmlRendererUtils.writePrettyLineSeparator(facesContext); // render days writeDays(facesContext, writer, inputCalendar, timeKeeper, currentDay, weekStartsAtDayIndex, weekDayOfFirstDayOfMonth, lastDayInMonth, weekdays); writer.endElement(HTML.TABLE_ELEM); }
From source file:org.onebusaway.webapp.actions.where.ScheduleAction.java
public List<String> getShortWeekDays() { List<String> result = new ArrayList<String>(); DateFormatSymbols dateFormatSymbols = new DateFormatSymbols(getLocale()); String shortWeekdays[] = dateFormatSymbols.getShortWeekdays(); Calendar calendar = Calendar.getInstance(getLocale()); int firstDayOfWeek = calendar.getFirstDayOfWeek(); for (int dayOfWeek = firstDayOfWeek; dayOfWeek < shortWeekdays.length; dayOfWeek++) { result.add(shortWeekdays[dayOfWeek]); }/* w w w . jav a 2s .c om*/ for (int dayOfWeek = Calendar.SUNDAY; dayOfWeek < firstDayOfWeek; dayOfWeek++) { result.add(shortWeekdays[dayOfWeek]); } return result; }