/** * 验证日期格式 * @return true 格式正确,false 格式错误 */ public static boolean checkDateformat(String dateStr){ String eL = "[0-9]{4}[-/]{1}[0-9]{2}[-/]{1}[0-9]{2}"; Pattern p = Pattern.compile(eL); Matcher m = p.matcher(dateStr); boolean flag = m.matches(); if (!flag) { System.out.println("格式错误"); }else{ System.out.println("格式正确"); } return flag; }