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 SimpleDateFormat parse method Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "SimpleDateFormat parse method" Watch "SimpleDateFormat parse method" New topic
Author

SimpleDateFormat parse method

Andy Hahn
Ranch Hand

Joined: Aug 31, 2004
Posts: 225
Hi,
I am having a problem with the parse method in SimpleDateFormat. I would expect the code below to catch a ParseException since the String textToParse is not a valid date. However, an exception is not thrown and a Date is returned. I would like to use this code to validate user input. Any suggestions? Thanks!

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 35241
    
    7
If you look at the javadocs of the parse method, you'll see that it may not use all of the text supplied. That's what is happening here. I'm not sure if this can be influenced by a call to "setLenient(false)", but it's worth a shot. If that doesn't work I'd suggest a regular expression for validation.


Android appsImageJ pluginsJava web charts
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: SimpleDateFormat parse method
 
Similar Threads
How to get tomorrow's date?
how do i get todays dat without the time
Convert String to Date
SimpleDateFormat parses illegal date string
Solution for Unparsable Date Exception