【发布时间】:2021-08-25 17:50:17
【问题描述】:
DateTimeFormatter fm = new DateTimeFormatterBuilder()
.appendPattern("MMMuuuu")
.parseDefaulting(ChronoField.YEAR, 2021)
.toFormatter(Locale.US);
List<LocalDate> datesMoreThan30 = new ArrayList<>();
List<LocalDate> datesLessThan30 = new ArrayList<>();
String fromDate = from;
String toDate = to;
LocalDate date1 = LocalDate.parse(fromDate,fm);
LocalDate date2 = LocalDate.parse(toDate,fm);
long days = ChronoUnit.DAYS.between(date1, date2);
if(days >= 30) {
datesMoreThan30.add(date1);
datesMoreThan30.add(date2);
}
else if(days < 30) {
datesLessThan30.remove(date1);
datesLessThan30.remove(date2);
}
以下是我不断遇到的错误。
3:21:31.183 [http-nio-8088-exec-1] ERROR o.a.c.c.C.[.[.[.[dispatcherServlet] - Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.time.format.DateTimeParseException: Text 'Jan2021' could not be parsed: Unable to obtain LocalDate from TemporalAccessor: {MonthOfYear=1, Year=2021},ISO of type java.time.format.Parsed] with root cause
java.time.DateTimeException:
【问题讨论】:
-
你能展示一些输入输出的例子吗,对不起,我没有得到你的问题
-
为什么标题中会提到“localDateTime”?
标签: java spring-boot