/**
* 校验日期格式是否正确
* @param s
* @return
*/
public static boolean isValidDate(String s)
{
try
{
dateFormat = new SimpleDateFormat("yyyy年MM月dd");
dateFormat.setLenient(false);
dateFormat.parse(s);
return true;
}
catch (Exception e)
{
//如果throw java.text.ParseException或者NullPointerException,就说明格式不对
return false;
}
}
/**
*main函数调用
*/
public static void main(String[] args) {
String startDate="2007年12月1日";
dateFormat = new SimpleDateFormat("yyyy年MM月dd");
dateFormat.setLenient(false);
if(isValidDate(startDate)){
System.out.println("对了");
}else{
System.out.println("不对");
}
5831

被折叠的 条评论
为什么被折叠?



