-2

I have to parse the following date: 2015-05-04 00:00:00.0 But my formatter can't recognize it.

DateTimeFormatter formatter = DateTimeFormatter.ofPattern("YYYY-MM-DD HH:MM:ss.S").withLocale(Locale.US);

I know it is the last character what is the problem, but don't really know what to put there.

REPARATUR
  • 5
  • 3
  • 2
    You might want to read the doc and the error message (hint: `MM` vs `mm`) –  May 31 '15 at 20:04

1 Answers1

0

The pattern you're looking for is: "YYYY-MM-DD HH:mm:ss.S", the key difference being the symbol used for minutes (you told it to parse them as months). From the javadoc of DateTimeFormat:

M/L     month-of-year               number/text       7; 07; Jul; July; J
m       minute-of-hour              number            30
1337joe
  • 2,327
  • 1
  • 20
  • 25
  • Unfortunately, this answer is wrong. The correct pattern is `yyyy-MM-dd HH:mm:ss.S` or even better `uuuu-MM-dd HH:mm:ss.S`. You can check [this answer](https://stackoverflow.com/a/67452253/10819573) to learn more about it. – Arvind Kumar Avinash May 09 '21 at 11:10