/**
* length是字符串长度
*sDate是字符串
*format是格式化样式。例如:yyyy-MM-dd HH:mm:ss
*/
public static boolean isLegalDate(int length,String sDate,String format){
int legalLen =length;
if(sDate==null||sDate.length()!=legalLen){
return false;
}
DateFormat formatter = new SimpleDateFormat(format);
try {
Date date = formatter.parse(sDate);
return sDate.equals(formatter.format(date));
} catch (ParseException e) {
return false;
}
}