public static boolean isValidDate(String str) {
boolean convertSuccess=true;
     // 指定日期格式为四位年/两位月份/两位日期,注意yyyy/MM/dd区分大小写;
SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd HH:mm");
try {
     // 设置lenient为false. 否则SimpleDateFormat会比较宽松地验证日期,比如2007/02/29会被接受,并转换成2007/03/01
format.setLenient(false);
format.parse(str);
} catch (ParseException e) {
// e.printStackTrace();
// 如果throw java.text.ParseException或者NullPointerException,就说明格式不对
convertSuccess=false;
}
return convertSuccess;
}

相关文章:

  • 2022-03-07
  • 2022-12-23
  • 2021-07-17
  • 2022-12-23
  • 2022-12-23
  • 2021-11-23
  • 2022-01-04
猜你喜欢
  • 2022-01-03
  • 2021-10-07
  • 2022-03-05
  • 2022-12-23
  • 2021-10-20
  • 2021-07-02
  • 2021-11-19
相关资源
相似解决方案