【发布时间】:2020-07-05 20:50:46
【问题描述】:
我有一个 DD/MM/YYYY 日期格式的字符串,我想检查新日期是否早于今天。我使用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");
}
异常文本:
线程“主”java.time.format.DateTimeParseException 中的异常:无法解析文本“02/12/1995”:无法从 TemporalAccessor 获取 LocalDate:{DayOfMonth=2, Year=1995, MinuteOfHour=12} ,java.time.format.Parsed 类型的 ISO
【问题讨论】:
标签: java date datetime exception localdate