Robert
Robert

Reputation: 1638

JodaTime dd-MMM-yyyy Pattern Exception

I have the following code

    DateTimeFormatter formatter = DateTimeFormat.forPattern("dd-MMM-yyyy").withLocale(Locale.US);       
formatter.parseDateTime("10-23-2012");

Why am I getting the following exception?

nested exception is java.lang.IllegalArgumentException: Invalid format: "10-23-2012" is malformed at "23-2012"

After reading the javadoc, I still can figure this out. The lowercase d (day of month) is supposed the represent minimum number of digits, but according to the exception it is getting truncated? Any ideas?

Upvotes: 0

Views: 1422

Answers (2)

Aravind Yarram
Aravind Yarram

Reputation: 80194

Try dd-MM-yyyy. Notice only two M's. Moreover, to parse 10-23-2012, the format should be MM-dd-yyy

Examples

MMM = Feb, Jul etc.

MM = 02, 07 etc.

Reference

Upvotes: 1

Robert Harvey
Robert Harvey

Reputation: 180858

There are three month characters in dd-MMM-yyyy but only two in 10-23-2012.

It gets worse. Your middle digits appear to be a day, not a month; and you probably want something like "OCT" there anyway.

Upvotes: 1

Related Questions