public static boolean checkDate(String date,String dateFormat){ if(date == null || date.trim().equals("")){ return false; } java.text.SimpleDateFormat phaser = new java.text.SimpleDateFormat( dateFormat); phaser.setLenient(false);//设置不能自动将不合法日期转换成合法日期 //例如:将2006-2-31转换为2006-3-3,setLenient默认是设为true,可以自动转换,现在设为false,就阻止了这种转换。 try{ if(phaser.parse(date) != null){//如果出现不合法的日期就会出异常 return true; } } catch(Exception e){ e.printStackTrace(); } return false; }
SimpleDateFormat
最新推荐文章于 2022-12-28 17:11:25 发布