Code example for SimpleDateFormat

Methods: applyLocalizedPattern

0
        // 
        // f2.applyLocalizedPattern("GuMtkHmsSEDFwWahKz"); 
        // String pattern = f2.toPattern(); 
        // assertTrue("Wrong pattern: " + pattern, pattern 
        //         .equals("GyMdkHmsSEDFwWahKz")); 
        // 
        // test the new "Z" pattern char 
        // f2 = new SimpleDateFormat("y", new Locale("de", "CH")); 
        // f2.applyLocalizedPattern("G u M t Z"); 
        // pattern = f2.toPattern(); 
        // assertTrue("Wrong pattern: " + pattern, pattern.equals("G y M d Z")); 
        // END android-removed 
 
        // test invalid patterns 
        try { 
            f2.applyLocalizedPattern("b");
            fail("Expected IllegalArgumentException for pattern with invalid pattern letter: b");
        } catch (IllegalArgumentException e) {
        } 
 
        try { 
            // ICU only! this fails on the RI 
            f2.applyLocalizedPattern("u");
            fail("Expected IllegalArgumentException for pattern with invalid pattern letter: u");
        } catch (IllegalArgumentException e) {
        } 
 
        try { 
            f2.applyLocalizedPattern("a '");
            fail("Expected IllegalArgumentException for pattern with unterminated quote: a '");
        } catch (IllegalArgumentException e) {
        } 
 
        try { 
            f2.applyLocalizedPattern(null);
            fail("Expected NullPointerException for null pattern");
        } catch (NullPointerException e) {
        } 
    } 
 
    /** 
     * java.text.SimpleDateFormat#applyPattern(java.lang.String) 
     */ 
    public void test_applyPatternLjava_lang_String() { 
        // Test for method void 
        // java.text.SimpleDateFormat.applyPattern(java.lang.String) 
        SimpleDateFormat f2 = new SimpleDateFormat("y", new Locale("de", "CH"));
        // BEGIN android-changed 
        f2.applyPattern("GyMdkHmsSEDFwWahKzZ");
        assertEquals("Wrong pattern", "GyMdkHmsSEDFwWahKzZ", f2.toPattern());
        // END android-changed