Reputation: 91949
I am doing the following
SimpleDateFormat formatter = new SimpleDateFormat("MM-dd-yyyy"); calendar.setTime(formatter.parse("01/26/2012");
When I do
calendar.getTime()
I see
java.text.ParseException: Unparseable date: "01/26/2012"
What is am I doing wrong?
Thank you
Upvotes: 1
Views: 1787
Reputation: 6173
You've set the format to MM-dd-yyyy And the you expect it to parse the string on a format: MM/dd/yyyy
Try
new SimpleDateFormat("MM/dd/yyyy");
Upvotes: 2
Reputation: 76888
Erm, you give the pattern
MM-dd-yyyy
to SimpleDateFormat
then offer it
01/26/2012
to parse. That's not the format you specified, and it's telling you it can't parse it.
You would need:
SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy");
Upvotes: 6