Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

DateFormat not throwing ParseException (lenient is set to false)

807580May 4 2010 — edited May 4 2010
Hi,

Can someone explain to me why the following does not throw a ParseException:
public class DateFormatTest {
    public static void main(String[] args) {
        //                 yyMMdd
        String dtString = "100504";

        java.text.DateFormat df = new java.text.SimpleDateFormat("MMddyyyy");
        df.setLenient(false);

        try {
            java.util.Date dt = df.parse(dtString);
            System.out.println(dtString  +" parsed: "+  dt);
        } catch(java.text.ParseException e) {
            e.printStackTrace();
        }
    }
}
Since DateFormat is using "MMddyyyy", the date string I'm passing in is only 6 bytes, and I'm setting lenient to false, it seems like parse() should throw a ParseException. Does anyone know what I'm missing?

Thank you.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 1 2010
Added on May 4 2010
2 comments
392 views