This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes java.util.Date question 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 » Beginning Java
Reply Bookmark "java.util.Date question" Watch "java.util.Date question" New topic
Author

java.util.Date question

Barun Saha
Greenhorn

Joined: Nov 10, 2003
Posts: 24
I have a jsp page where I accept the date. Then I want to test if the date is valid or not. Here I have an Invlid date, but the output show the date as 04-05-2004.
Is this s bug or I am not doing something right?.

Thanks,
Barun

<% SimpleDateFormat sm = new SimpleDateFormat("MM-dd-yyyy");
java.util.Date dt = null;
dt = sm.parse("03-36-2004"); %>

<%=sm.format(dt)%>
chi Lin
Ranch Hand

Joined: Aug 24, 2001
Posts: 348
to activate validity check, add one more line sm.setLenient(false)
Alessandro Siprian
Greenhorn

Joined: Feb 24, 2003
Posts: 1
What happens when a date is entered like 3/36/04 it takes the amount of days past 31 for the 3rd month in your case 5 more than 31 and rolls it over to the next month and adds 5 days. This is good for adding days when you don't know the amount of days in the month.
Barun Saha
Greenhorn

Joined: Nov 10, 2003
Posts: 24
Thanks, the setLenient(false) worked!!.
 
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: java.util.Date question
 
Similar Threads
Problems with custom xsd:dateTime conversion
Error 500 Unable to compile
Unparseable Date
CustomEditorConfigurer Exception
Convert String to Date