It's not a secret anymore!
The moose likes Java in General and the fly likes Date parsing error..??? 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 "Date parsing error..???" Watch "Date parsing error..???" New topic
Author

Date parsing error..???

Gaurav Jain
Ranch Hand

Joined: Mar 11, 2004
Posts: 108
I have a string coming in the format OCT/15/2004.
I have to convert this in to a date object.
I am using th following code:
SimpleDateFormat sdf = new SimpleDateFormat("MMM/DD/yyyy");
value="Jul/13/2004";
sdf.parse(value));
Here value is OCT/15/2004.
The date object i get is Jan/13/2004.
No matter what month is passed the parsed date object always has the month as Jan.
What is going wrong?
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8261

Works fine for me.





"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Pavan Panduga
Ranch Hand

Joined: Jun 12, 2002
Posts: 68
Hi Gaurav,

take a look at javadoc of SimpleDateFormat for defined formats.



new SimpleDateFormat("MMM/DD/yyyy"); is different from
new SimpleDateFormat("MMM/dd/yyyy");

hope this helps,
Pavan
Gaurav Jain
Ranch Hand

Joined: Mar 11, 2004
Posts: 108
Thanks it worked for me now.
dd instead of DD did the trick
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Date parsing error..???
 
Similar Threads
java.text.SimpleDateFormat
date.after() problem
Date,Calendar?help!!!!
How to get weeks for a particular year with Calendar object
convert a String to a Date