Java8的DateTimeFormatter
使用DateTimeFormatter进行yyyyMMddHHmmss格式化的时候没有问题,但是包括毫秒yyyyMMddHHmmssSSS的时候就会出现DateTimeParseException
问题描述:
当使用类似以下的代码的时候会现现此问题
String input = "20111203123456789";
DateTimeFormatter dtf = DateTimeFormatter.ofPattern( "yyyyMMddHHmmssSSS");
LocalDateTime localDateTime = LocalDateTime.parse(input, dtf);//Error!
System.out.println(localDateTime);
异常信息
Exception in thread "main" java.time.format.DateTimeParseException: Text '20111203123456789' could not be parsed at index 0
at java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:1947)
at java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1849)
at java.time.LocalDateTime.parse(LocalDateTime.java