求判断输入日期是否大于本月最后一天的方法例如:输入日期为2007-06-31 怎样判断其正确性呢?跪求

解决方案 »

  1.   

    SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
        try{
          String time = "2007-06-31";
          Date date = sf.parse("2007-06-31");
          String timeAfter = sf.format(date);
          System.out.println(time.equals(timeAfter));
        }catch(Exception e){
          System.out.println(e.getLocalizedMessage());
        }
      

  2.   

    Calendar c = Calendar.getInstance();
    c.setTime(new Date());
    int nowYear = c.get(Calendar.YEAR);
    int nowMonth = c.get(Calendar.MONTH);
    c.set(Calendar.MONTH, nowMonth + 1);
    c.set(nowYear, nowMonth, 0, 23, 59, 59);
    Date nextDate1 = c.getTime();
    c.set(Calendar.DAY_OF_MONTH, c.get(Calendar.DAY_OF_MONTH) - 1);
    Date nextDate2 = c.getTime();
    if (inputDate.after(nextDate1)){
      System.out.println(">");
    }else if(inputDate.before(nextDate2)){
      System.out.println("<");
    }else{
      System.out.println("=");
    }
      

  3.   

    上面代码多了一行~不过不影响~
    c.set(Calendar.MONTH, nowMonth + 1);
    删了也可