wood burning stoves 2.0*
The moose likes Java in General and the fly likes parse method of SimpleDateFormat is not throwing exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "parse method of SimpleDateFormat is not throwing exception" Watch "parse method of SimpleDateFormat is not throwing exception" New topic
Author

parse method of SimpleDateFormat is not throwing exception

Abdul Mohsin
Ranch Hand

Joined: Apr 26, 2007
Posts: 111

Hi,

Parse method of SimpleDateFormat is not giving any exception when wrong month say(20) passed to it.
I am not able to find any way get the exception if wrong month is passed to it.


SimpleDateFormat format = new SimpleDateFormat( "MM_dd_yyyy_HH_mm_ss" );
ParsePosition pos= new ParsePosition(0);
format.parse("20_12_2007_05_23_13",pos); // month is passed as 20
System.out.println("After parsing error index:"+pos.getErrorIndex());
System.out.println(" Parse index:"+pos.getIndex());


This code compiles and run perfectly and not throw any exception inspire of passing month as 20.

Please help..

Regards,

Abdul Mohsin


Regards, Abdul Mohsin
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39537
    
  27
Try turning off lenient processing by calling


Ping & DNS - updated with new look and Ping home screen widget
Abdul Mohsin
Ranch Hand

Joined: Apr 26, 2007
Posts: 111

Thanks a lot , it works.

Regards,

Abdul Mohsin
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: parse method of SimpleDateFormat is not throwing exception
 
Similar Threads
date format in java
Date validation
How to parse a user-entered Date into a Date or Calendar object
How to get current date and time
Validating date using regex and simple date format