I don't understand something, I have this code :
DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS");
System.out.println(LocalDateTime.parse(LocalDateTime.now().format(fmt), fmt));
This generate and exception :
Exception in thread "main" java.time.format.DateTimeParseException: Text '20200605102607066' could not be parsed at index 0
at java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:1949)
at java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1851)
at java.time.LocalDateTime.parse(LocalDateTime.java:492)
at Test.main(AccountPasswordHistoryTypeHandler.java:102)
But if I change the pattern to have a separator between date part and time part : "yyyyMMdd_HHmmssSSS"
it works as expected.
Why is a formatter can't parse its own result ?
It is a bug in Java8 check this :
JDK-8031085 : DateTimeFormatter won't parse dates with custom format "yyyyMMddHHmmssSSS"
It was fixed in the new version.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With