Code example for SimpleDateFormat

Methods: formatgetDateFormatSymbolssetDateFormatSymbols

        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(
        try { 
            fail("NullPointerException was not thrown.");
        } catch(NullPointerException npe) {
    public void test_toLocalizedPattern() { 
        // BEGIN android-changed 
        // Test for method java.lang.String 
        // java.text.SimpleDateFormat.toLocalizedPattern() 
        SimpleDateFormat f2 = new SimpleDateFormat("GyMdkHmsSEDFwWahKzZ",
                new Locale("de", "CH"));
        String pattern = f2.toLocalizedPattern();
        // the default localized pattern characters are the same for all locales 
Contextual code suggestions in your IDE  Get Codota for Java