0

Possible Duplicate:
Compare dates in Java

I need compare two dates date1 and date2, the condition is:

  1. date1 < date2
  2. date1 + 14Month <= date2

For the first condition im using if(date2.after(date1))

But for the second I'm not sure...

I'm using Calendar calendar = Calendar.getInstance(); calendar.setTime(fecha1); calendar.add(Calendar.MONTH, +14); Date nuevaFecha1 = (Date) calendar.getTime();

some idea how validate this

Community
  • 1
  • 1
ale
  • 3,301
  • 10
  • 40
  • 48

1 Answers1

0

Try this

    Calendar calendar1 = Calendar.getInstance(); 
    calendar1.set(Calendar.YEAR, year);
    calendar1.set(Calendar.MONTH, month );
    calendar1.set(Calendar.DAY_OF_MONTH, day);  

    Calendar calendar2 = Calendar.getInstance(); 
    calendar2.set(Calendar.YEAR, year);
    calendar2.set(Calendar.MONTH, month );
    calendar2.set(Calendar.DAY_OF_MONTH, day); 

    long mills1 = calendar1.getTimeInMillis();
    long mills2 = calendar2.getTimeInMillis();

    if(mills1 > mills2){

    }else{
    }
Parag Chauhan
  • 35,760
  • 13
  • 86
  • 95
  • Month range is 0-11 ,suppose now january so its no is 0 + 14 = 14 ,means 1 yr + 3 month so u want to add like year +1 and month 3 – Parag Chauhan Oct 09 '12 at 05:22