目前我有一种方法可以查看当前日期并与输入日期进行比较。我正在使用 java.time API。我得到一个 DateTimeParseException ,我无法解析索引 0 处的文本值。下面是我到目前为止的代码:
public static boolean isWeekStartFormatValid(String value) {
value = Util.getTrimmedValue(value);
//In constants public static final String DATE_FORMAT = "MM/dd/yyyy";
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(Constants.DATE_FORMAT);
LocalDate currentDate = LocalDate.now();
LocalDate inputDate = LocalDate.parse(value, formatter);
if(inputDate.isAfter(currentDate) && inputDate.getDayOfWeek() == DayOfWeek.SATURDAY) {
return true;
}
return false;
}
当我输入 2020 年 8 月 19 日的值时,我收到以下错误:
[err] 原因:java.time.format.DateTimeParseException:无法在索引 0 处解析文本“8/19/2020”[err] at java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:1949) [错误] 在 java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1851) [错误] 在 java.time.LocalDate.parse(LocalDate.java:400)
有什么我做的不对吗?应该对这样的事情进行尝试吗?不知道该怎么办。任何建议表示赞赏。