Java Code Examples for java.text.SimpleDateFormat#getDateFormatSymbols()

The following examples show how to use java.text.SimpleDateFormat#getDateFormatSymbols() . 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: SimpleDateFormatTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
public void test_setDateFormatSymbolsLjava_text_DateFormatSymbols() {
    // Test for method void
    // java.text.SimpleDateFormat.setDateFormatSymbols(java.text.DateFormatSymbols)
    SimpleDateFormat f1 = new SimpleDateFormat("a");
    DateFormatSymbols symbols = new DateFormatSymbols();
    symbols.setAmPmStrings(new String[] { "morning", "night" });
    f1.setDateFormatSymbols(symbols);
    DateFormatSymbols newSym = f1.getDateFormatSymbols();
    assertTrue("Set incorrectly", newSym.equals(symbols));
    assertTrue("Not a clone", f1.getDateFormatSymbols() != symbols);
    String result = f1.format(new GregorianCalendar(1999, Calendar.JUNE, 12, 3, 0).getTime());
    assertEquals("Incorrect symbols used", "morning", result);
    symbols.setEras(new String[] { "before", "after" });
    assertTrue("Identical symbols", !f1.getDateFormatSymbols().equals(symbols));

    try {
        f1.setDateFormatSymbols(null);
        fail();
    } catch (NullPointerException expected) {
    }
}
 
Example 2
Source File: UIFenixCalendar.java    From fenixedu-academic with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void encodeMonthRow(ResponseWriter writer, Calendar date, Locale locale) throws IOException {
    // writer.startElement("tr", this);
    // writer.startElement("td", this);
    writer.startElement("caption", this);
    writer.writeAttribute("style", "font-weight: 600; background: #bbb", null);
    writer.writeAttribute("class", "text-center", null);
    // writer.writeAttribute("colspan", 6, null);

    SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm", locale);
    DateFormatSymbols dfs = sdf.getDateFormatSymbols();
    writer.write((dfs.getMonths())[date.get(Calendar.MONTH)]);

    writer.endElement("caption");
    // writer.endElement("td");
    // writer.endElement("tr");
}
 
Example 3
Source File: MPXJBaseFormat.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Allows the AM/PM text to be set.
 *
 * @param am AM text
 * @param pm PM text
 */
public void setAmPmText(String am, String pm)
{
   for (SimpleDateFormat format : m_formats)
   {
      DateFormatSymbols symbols = format.getDateFormatSymbols();
      symbols.setAmPmStrings(new String[]
      {
         am,
         pm
      });
      format.setDateFormatSymbols(symbols);
   }
}
 
Example 4
Source File: SimpleDateFormatTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
public void test_getDateFormatSymbols() {
    // Test for method java.text.DateFormatSymbols
    // java.text.SimpleDateFormat.getDateFormatSymbols()
    SimpleDateFormat df = (SimpleDateFormat) DateFormat.getInstance();
    DateFormatSymbols dfs = df.getDateFormatSymbols();
    assertTrue("Symbols identical", dfs != df.getDateFormatSymbols());
}
 
Example 5
Source File: UIFenixCalendar.java    From fenixedu-academic with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void encodeDaysOfWeek(ResponseWriter writer, Locale locale) throws IOException {
    writer.startElement("tr", this);

    SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm", locale);
    DateFormatSymbols dfs = sdf.getDateFormatSymbols();

    encodeDayOfWeek(writer, (dfs.getWeekdays())[Calendar.MONDAY]);
    encodeDayOfWeek(writer, (dfs.getWeekdays())[Calendar.TUESDAY]);
    encodeDayOfWeek(writer, (dfs.getWeekdays())[Calendar.WEDNESDAY]);
    encodeDayOfWeek(writer, (dfs.getWeekdays())[Calendar.THURSDAY]);
    encodeDayOfWeek(writer, (dfs.getWeekdays())[Calendar.FRIDAY]);
    encodeDayOfWeek(writer, (dfs.getWeekdays())[Calendar.SATURDAY]);

    writer.endElement("tr");
}
 
Example 6
Source File: DateChooser.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Sets a new locale to use for calendar. Locale will define the names of
 * months and days, and the first day of week.
 *
 * @param locale new locale (must not be null)
 */
public void setLocale(Locale locale) {
	checkWidget();
	if (locale == null) {
		SWT.error(SWT.ERROR_NULL_ARGUMENT);
	}

	this.locale = locale;

	// Loads the resources
	resources = ResourceBundle.getBundle(BUNDLE_NAME, locale);
	prevMonth.setToolTipText(resources.getString("DateChooser.previousButton")); //$NON-NLS-1$
	nextMonth.setToolTipText(resources.getString("DateChooser.nextButton")); //$NON-NLS-1$

	// Defines formats
	df1 = new SimpleDateFormat("MMMM yyyy", locale); //$NON-NLS-1$
	df2 = DateFormat.getDateInstance(DateFormat.SHORT, locale);
	final Calendar c = Calendar.getInstance(TimeZone.getDefault(), locale);
	firstDayOfWeek = c.getFirstDayOfWeek();
	minimalDaysInFirstWeek = Integer.parseInt(resources.getString("minimalDaysInFirstWeek"));
	if (currentMonthCal != null) {
		currentMonthCal.setFirstDayOfWeek(firstDayOfWeek);
		currentMonthCal.setMinimalDaysInFirstWeek(minimalDaysInFirstWeek);
	}
	if (todayCal != null) {
		todayCal.setFirstDayOfWeek(firstDayOfWeek);
		todayCal.setMinimalDaysInFirstWeek(minimalDaysInFirstWeek);
	}

	// Sets the header menu items
	final String[] months = df1.getDateFormatSymbols().getMonths();
	final MenuItem[] items = monthsMenu.getItems();
	for (int i = 0; i < 12; i++) {
		items[i].setText(months[i]);
	}

	// Sets the grid header initials
	redrawInc();
	final DateFormatSymbols symboles = df1.getDateFormatSymbols();
	final String[] sn = symboles.getShortWeekdays();
	final String[] ln = symboles.getWeekdays();
	int f = firstDayOfWeek;
	for (int i = 1; i < headers.length; i++) {
		headers[i].setText(sn[f].substring(0, 1).toUpperCase());
		headers[i].setToolTipText(ln[f]);
		f = f % 7 + 1;
	}

	// Updates the footer
	updateTodayLabel();

	refreshDisplay();
	redrawDec();
}
 
Example 7
Source File: I18nFormat.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void init()
{
    String[] months = { "month.january", "month.february", "month.march", "month.april", "month.may", "month.june",
        "month.july", "month.august", "month.september", "month.october", "month.november", "month.december" };
    String[] shortMonths = { "month.short.january", "month.short.february", "month.short.march",
        "month.short.april", "month.short.may", "month.short.june", "month.short.july", "month.short.august",
        "month.short.september", "month.short.october", "month.short.november", "month.short.december" };
    String[] weekdays = { "weekday.sunday", "weekday.monday", "weekday.tuesday", "weekday.wednesday",
        "weekday.thursday", "weekday.friday", "weekday.saturday" };
    String[] shortWeekdays = { "weekday.short.sunday", "weekday.short.monday", "weekday.short.tuesday",
        "weekday.short.wednesday", "weekday.short.thursday", "weekday.short.friday", "weekday.short.saturday" };

    String calendarName = PeriodType.getCalendar().name() + ".";

    for ( int i = 0; i < 12; ++i )
    {
        if ( resourceBundle.containsKey( calendarName + months[i] ) )
        {
            months[i] = resourceBundle.getString( calendarName + months[i] );
        }
        else
        {
            months[i] = resourceBundle.getString( months[i] );
        }

        if ( resourceBundle.containsKey( calendarName + shortMonths[i] ) )
        {
            shortMonths[i] = resourceBundle.getString( calendarName + shortMonths[i] );
        }
        else
        {
            shortMonths[i] = resourceBundle.getString( shortMonths[i] );
        }
    }

    for ( int i = 0; i < 7; ++i )
    {
        if ( resourceBundle.containsKey( calendarName + weekdays[i] ) )
        {
            weekdays[i] = resourceBundle.getString( calendarName + weekdays[i] );
        }
        else
        {
            weekdays[i] = resourceBundle.getString( weekdays[i] );
        }

        if ( resourceBundle.containsKey( calendarName + shortWeekdays[i] ) )
        {
            shortWeekdays[i] = resourceBundle.getString( calendarName + shortWeekdays[i] );
        }
        else
        {
            shortWeekdays[i] = resourceBundle.getString( shortWeekdays[i] );
        }
    }

    SimpleDateFormat dateFormat = new SimpleDateFormat();
    dateFormatSymbols = dateFormat.getDateFormatSymbols();

    dateFormatSymbols.setMonths( months );
    dateFormatSymbols.setShortMonths( shortMonths );
    dateFormatSymbols.setWeekdays( weekdays );
    dateFormatSymbols.setShortWeekdays( shortWeekdays );
}