Hello. There is such a format:

DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.A"); 

When trying to parse the string: '2015-12-15 09: 41: 51.0', throws an exception:

 java.time.format.DateTimeParseException: Text '2015-12-15 09:41:51.0' could not be parsed: Conflict found: HourOfDay 9 differs from HourOfDay 0 while resolving SecondOfDay at java.time.format.DateTimeFormatter.createError(DateTimeFormatter.java:1920) at java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1855) at java.time.LocalDateTime.parse(LocalDateTime.java:492) 

What could be the problem?

  • one
    I would check the pattern. SecondOfDay - suspicious. What it is? How many seconds have passed since the beginning of the day? Why do you need it? Maybe the format makes you recognize SecondOfDay, which is not even close in the string. - Sergey
  • @Sergey checked, docs.oracle.com/javase/8/docs/api/java/time/format/... there is not a word about SecondOfDay at all. - Maxim Drobyshev
  • That's what it says there A - milli-of-day Probably this is the point. It should be S - fraction-of-second , I think. yyyy-MM-dd HH:mm:ss.S - Sergey
  • @Sergey oh what a stupid mistake. Thank you very much. - Maxim Drobyshev

0