File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Simple Date Format problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Simple Date Format problem" Watch "Simple Date Format problem" New topic
Author

Simple Date Format problem

Suhas Bilaye
Ranch Hand

Joined: Sep 10, 2009
Posts: 80
Hi All,

I am using the Simple Date format java class to format a date. I dont get any exception as the format of the date I am entering is correct. But if I enter a date like "23/23/2001" where the date format defined is "dd/MM/yyyy" the date is parsed successfully as 23 Nov 2001. But i want that some exception or errors should be thrown as the month is out of range.

Can anyone tell me how do i go about it?

Regards,
Suhas


Thanks and Regards,
Suhas
http://www.xplore-java.blogspot.com/
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19655
    
  18

Call setLenient(false) on the DateFormat object. By default, Calendar and DateFormat objects are lenient, meaning they will overflow when an invalid date is encountered. If the leniency is set to false an IllegalArgumentException is thrown instead.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Suhas Bilaye
Ranch Hand

Joined: Sep 10, 2009
Posts: 80
Hey,
Thanks a lot.
I forgot to mention that the SimpleDateFormat class is not of the java.text package but it is of the org.gwtwidgets.client.util package. This class can be used on client side when coding is to be done using GWT (Google Web Toolkit). It compliments the SimpleDateFormat class of the java.text package but the problem is that this class does not have the setLenient(<boolean>) method in it.

Regards,
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Simple Date Format problem
 
Similar Threads
Problem with day light savings in Simple Date Formatter
java.util.Date
is date valid
Date Format Problem
Display date format by calendar entry