# 不能用LocalDate.parse(),解析不了20230231,默认会解析成20230228,并且不抛异常,用Strict模式,虽然会抛异常但无法解析20230201,推荐下面的
public static boolean isValidDateFormat(String date, String format) {
if(date.length!=format.length){
return false;
}
try {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(format);
LocalDate.parse(date, formatter);
return true;
} catch (DateTimeParseException e) {
return false;
}
}
标签:parse,return,format,校验,---,date,Java,解析
From: https://www.cnblogs.com/hujunwei/p/17865700.html