5
java.time.LocalDateTime success = java.time.LocalDateTime.parse("20 01 2014 15 36 21 234",java.time.format.DateTimeFormatter.ofPattern("dd MM yyyy HH mm ss SSS"));             
java.time.LocalDateTime fails   = java.time.LocalDateTime.parse("20012014153621234",java.time.format.DateTimeFormatter.ofPattern("ddMMyyyyHHmmssSSS"));

reference: http://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html

Question: The formatter/parser seems to not distinguisch between fixed and variable items. eg. d="day-of-month" used as "dd" could be one or two digits (eg. 8 or 18). Therefore the parser does not use "fixed" lengths as it tries to parse the next "item". But the "items" are not separated and the parsing fails.

Am i right? Is there a fix for this?

Edit: Interestingly this works:

java.time.LocalDate date1   = java.time.LocalDate.parse("20140120", java.time.format.DateTimeFormatter.ofPattern("yyyyMMdd"));
java.time.LocalTime time1   = java.time.LocalTime.parse("153621234", java.time.format.DateTimeFormatter.ofPattern("HHmmssSSS"));

but why not for Date+Time ?

Mister Smith
  • 27,417
  • 21
  • 110
  • 193
Bernhard
  • 2,541
  • 1
  • 26
  • 24
  • 1
    possible duplicate of [Is java.time failing to parse fraction-of-second?](http://stackoverflow.com/questions/22588051/is-java-time-failing-to-parse-fraction-of-second) – Mister Smith Jul 18 '14 at 11:50
  • What about my description @MisterSmith? I did not found suitable explanation in the reference provided by you!!! – Am_I_Helpful Jul 18 '14 at 12:00
  • 3
    @shekharsuman The explanation is that this is a bug. There's even a [JDK issue](https://bugs.openjdk.java.net/browse/JDK-8031085) linked in the accepted answer. – Mister Smith Jul 18 '14 at 12:17
  • @MisterSmith It certainly looks like a Java 8 bug since the code runs fine on Java 9. – skomisa Oct 05 '17 at 19:09

0 Answers0