问题描述:
java.time.format.DateTimeParseException: Text '20220310' could not be parsed at index 0
问题分析:
1、使用 LocalDate.parse() 方法时,要转换的日期字符串格式和指定的日期格式对不上。
LocalDate.parse("20220310", DateTimeFormatter.ofPattern("yyyy-MM-dd"));
解决办法:
要转换的日期字符串格式和指定的日期格式一致即可。
LocalDate.parse("2022-03-10", DateTimeFormatter.ofPattern("yyyy-MM-dd"));