julienasefth julienasefth - 4 months ago 35
Groovy Question

Java parsing date

Hello i am currently looking for parsing a date in groovy/java

the format is "June 13 2003" ( not so exotic !!! )

A simple look at http://docs.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html give me some clues

Month: If the number of pattern letters is 3 or more, the month is interpreted as text; otherwise, it is interpreted as a number.

Year : if the number of pattern letters is more than 2, the year is interpreted literally

So i would guess that "MMMM d yyyy" is fine
But even trying other patterns : "MMM d yyyy","M d yyyy","MMM dd yyyy", none of them works .......

Date dateParsed = new SimpleDateFormat("MMMM d yyyy").parse("June 13 2003")
println dateParsed

gives me an exception :

Exception in thread "main" java.text.ParseException: Unparseable date: "June 13 2003"


Your formats should work, the problem might be locale - if your system is not in english locale by default, it tries to parse your local month names, instead of the english variants.


new SimpleDateFormat("MMMM dd yyyy", java.util.Locale.ENGLISH)