Dan MacBean
Dan MacBean

Reputation: 1925

JodaTime Formatter confusion

When I retrieve a date from a string e.g. "Sat 11 Feb" using Jodatime formatting classes:

DateTimeFormatter formatter = DateTimeFormat.forPattern("EE dd MMM");

I get back a date (after parsing) of: "Saturday, 12 February 00:00"

Can anyone explain this? I would expect a DateMidnight for the 11th not the 12th.

This is the code I am using:

private static String STYLE = "EE dd MMM";
private static DateTimeFormatter formatter = DateTimeFormat.forPattern(STYLE);
public static DateTime getDate(String str) {
return formatter.parseDateTime(str);
}

String dateExample = "Sat 11 Feb";
log.info(dateExample);
DateTime eventDate = getDate(dateExample);
log.info(eventDate.toString());

And this is what is logged:

2012-02-09_11:12:40.592 INFO - Sat 11 Feb

2012-02-09_11:12:40.664 INFO - 2000-02-12T00:00:00.000Z

Upvotes: 0

Views: 236

Answers (1)

David Grant
David Grant

Reputation: 14223

11 Feb 2000 was a Friday, not a Saturday.

Upvotes: 2

Related Questions