user962206
user962206

Reputation: 16117

Incorrect Joda Time parsing of String to LocalDate

Here's the string I'm trying to format

10-12-2015

Which stands for october 12 2015. However when I'm parsing it as a a LocalDate. using this

LocalDate ld = LocalDate.parse(dto.getTargetDate(), DateTimeFormat.forPattern("mm-dd-yyyy"))

the result is always 2015-01-12

What am I doing wrong?

Upvotes: 0

Views: 255

Answers (2)

Igor Tyulkanov
Igor Tyulkanov

Reputation: 5548

Just change mm to MM, because mm is for minutes.

Thus, when parsing you put a year equal to 2015, day to 12 and minutes to 10. All other fields are default values, month is January, hours - 00, and so on. That's why you get 12 January 2015.

Upvotes: 3

Andreas
Andreas

Reputation: 159086

Month is uppercase M. The lowercase m is minute.

Upvotes: 1

Related Questions