views:

316

answers:

1

I tried

    DateFormat fmt = new SimpleDateFormat("MMMM dd, yyyy");
    Date d = fmt.parse("June 27,  2007");

Exception in thread "main" java.text.ParseException: Unparseable date: "June 27, 2007"

The java docs say i should use four characters to match the full form. I'm only able to use MMM successfully with abbreviated months like "Jun" but i need to match full form.

Text: For formatting, if the number of pattern letters is 4 or more, the full form is used; otherwise a short or abbreviated form is used if available. For parsing, both forms are accepted, independent of the number of pattern letters.

http://java.sun.com/j2se/1.6.0/docs/api/java/text/SimpleDateFormat.html

+2  A: 

You are probably using a locale where the month names are not "January", "February", etc. but some other words in your local language.

Try specifying the locale you wish to use, for example Locale.US:

DateFormat fmt = new SimpleDateFormat("MMMM dd, yyyy", Locale.US);
Date d = fmt.parse("June 27,  2007");

Also, you have an extra space in the date string, but actually this has no effect on the result. It works either way.

Mark Byers
so does the extra space have some influence in the parse error?
Beau Martínez
@Beau Martínez: No, that has no effect whatsoever. I've updated my comment to address that point since it has been brought up not just by you, but by others in the comments too.
Mark Byers