String eL = "[0-9]{4}-[0-9]{2}-[0-9]{2}"; Pattern p = Pattern.compile(eL); Matcher m = p.matcher(date); boolean dateFlag = m.matches(); if (!dateFlag) { System.out.println("格式错误"); } System.out.println("格式正确");