我有一个带有DD/MM/YYYY日期格式的字符串,我想检查新的date 是否比现在的更旧。然而,我使用LocalDate.now();时,在运行以下代码时有一个异常:
LocalDate today = LocalDate.now();
DateTimeFormatter FORMATO_DIA = DateTimeFormatter.ofPattern("dd/mm/yyyy");
String otherDay = "02/12/1995";
LocalDate otherDay2 = LocalDate.parse(otherDay, FORMATO_DIA);
if (today.isBefore(otherDay2)){
System.out.println("NICE");
}例外案文:
线程"main“java.time.format.DateTimeParseException中的异常:文本'02/12/1995‘无法解析:无法从TemporalAccessor获得LocalDate:{DayOfMonth=2、Year=1995、MinuteOfHour=12}、java.time.format.Parsed类型的ISO
发布于 2019-02-27 01:07:56
这是因为您使用的是mm,它代表几分钟。您必须在月内使用MM
https://stackoverflow.com/questions/54896499
复制相似问题