异常: Text ‘20201217‘ could not be parsed: Unable to obtain ..

时间:2025-03-17 20:58:15

错误类型:: Text '20201217' could not be parsed: Unable to obtain LocalDateTime from TemporalAccessor: {},ISO resolved to 2020-12-17 of type

String time = "20201217";
DateTimeFormatter dateFormat = ("yyyyMMdd");
LocalDateTime date = (time, dateFormat);


代码中,定义的time为yyyyMMdd, 在DateTimeFormatter时的格式是yyyyMMdd,这类错误是LocalDateTime类要求必须有yyyyMMddHHmmss格式,把LocalDateTime换为LocalDate,错误解决
 总结: LocalDateTime其实是 LocalDate + LocalTime 两部分都得有,不然会报错