public static boolean isRqSjFormat(String mes){
String format = "([0-9]{4})(0[1-9]|1[012])(0[1-9]|[12][0-9]|3[01])"
+ "([01][0-9]|2[0-3])[0-5][0-9][0-5][0-9]";
Pattern pattern = Pattern.compile(format);
Matcher matcher = pattern.matcher(mes);
if (matcher.matches()) {
pattern = Pattern.compile("(\\d{4})(\\d{2})(\\d{2}).*");
matcher = pattern.matcher(mes);
if (matcher.matches()) {
int y = Integer.valueOf(matcher.group(1));
int m = Integer.valueOf(matcher.group(2));
int d = Integer.valueOf(matcher.group(3));
if (d > 28) {
Calendar c = Calendar.getInstance();
c.set(y, m-1, 1);
//每个月的最大天数
int lastDay = c.getActualMaximum(Calendar.DAY_OF_MONTH);
return (lastDay >= d);
}
}
return true;
}
return false;
}
日期验证工具类
最新推荐文章于 2023-12-27 17:38:01 发布