可以的,设定一个参数即可
比如
    DateFormat dateFormat;
    dateFormat = new SimpleDateFormat("yyyy-MM-dd kk:mm:ss", Locale.ENGLISH);
    dateFormat.setLenient(false);
    java.util.Date timeDate = dateFormat.parse(dateString);
    //转换为util类型看到dateFormat.setLenient(false);没有,设定其为false就是强制判断是否非法日期,不让系统自动转换,否则2月31号系统会自动转换为3月2号或者3号

解决方案 »

  1.   

    public static boolean validateDate(int nYear,int nMonth,int nDate) {
        Calendar time = Calendar.getInstance();
        time.set(Calendar.YEAR,nYear);
        time.set(Calendar.MONDAY,nMonth-1);
        time.set(Calendar.DAY_OF_MONTH,nDate);
        return time.get(Calendar.YEAR)==nYear
                &&(time.get(Calendar.MONDAY)+1)==nMonth
                &&time.get(Calendar.DAY_OF_MONTH)==nDate;
      }
      

  2.   

    用SimpleDateFormat的方法setLenient(false);