*
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
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: 41188
    
  45
Try turning off lenient processing by calling


Ping & DNS - my free Android networking tools app
Abdul Mohsin
Ranch Hand

Joined: Apr 26, 2007
Posts: 111

Thanks a lot , it works.

Regards,

Abdul Mohsin
 
wood burning stoves
 
subject: parse method of SimpleDateFormat is not throwing exception
 
Similar Threads
How to parse a user-entered Date into a Date or Calendar object
date format in java
Validating date using regex and simple date format
How to get current date and time
Date validation