如何判断两个日期不相差三个月

解决方案 »

  1.   

    public boolean isLess90Days(Date d1,Date d2){
    return Math.abs(d1.getTime()-d2.getTime())<24*60*60*1000*90;
    }
      

  2.   

    多谢tg008007x3, 应该就像下面这个代码一样, Date startDate = employee.getJoinDate();
    Date endDate = employee.getResignDate();

    Calendar endCalendar = Calendar.getInstance();
    endCalendar.setTime(endDate);
    endCalendar.add(Calendar.MONTH, -3);

    if (endCalendar.getTime().before(startDate)) {
    addActionError("The interval of start date and end date should no more than 3 months");
    }
      

  3.   


    start.add(Calendar.MONTH, 3);
    if(start.befor){
    System.out.println("相隔没有3个月!!");{
    else System.out.println("至少相隔3个月");
      

  4.   

    start.add(Calendar.MONTH, 3);
    if(start.befor(end)){
    System.out.println("相隔没有3个月!!");{
    else System.out.println("至少相隔3个月");