The following code will fail with a DateTimeParseException
DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS");
LocalDateTime now = LocalDateTime.now();
System.out.println(now);
String s = format.format(now);
System.out.println(s);
System.out.println(LocalDateTime.parse(s, format));
whereas the following code will work:
DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyyMMddHHmmss.SSS");
LocalDateTime now = LocalDateTime.now();
System.out.println(now);
String s = format.format(now);
System.out.println(s);
System.out.println(LocalDateTime.parse(s, format));
The only difference is the "." in the second pattern.
Unfortunately my input data is like the first pattern and I can parse such times with an "old" SimpleDateFormat with the very same pattern.
The question is: why does the new DateTimeFormatter fail here and is there a fix for this?