驾驶证添加起始截止日期格式判断

This commit is contained in:
2024-12-31 11:03:17 +08:00
parent 7d86e5cbc6
commit 205a6ee7f5
2 changed files with 38 additions and 2 deletions
@@ -307,6 +307,27 @@ public final class TimeUtil {
return format.format(date);
}
/**
* 验证时间字符串是否是yyyy-MM-dd格式
*
* @param dateStr 需要验证的时间字符串
* @return 如果是yyyy-MM-dd格式,返回true;否则返回false
*/
public static boolean isValidDate(String dateStr) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
sdf.setLenient(false); // 设置不宽容,严格解析
try {
Date date = sdf.parse(dateStr);
// 可以进一步验证解析后的日期是否合法(例如:检查月份天数、闰年等)
// 但对于简单的格式验证,这一步通常不是必需的
return true;
} catch (ParseException e) {
return false;
}
}
/**
* 将Date类型转为时间戳
*