So something along the lines of...
Calendar cal = Calendar.getInstance();
cal.setTime(startDate);
cal.add(Calendar.MONTH, duration);
Date endDate = cal.getTime();
Date today = new Date();
// You also want to check for today.equals(endDate)
if (today.before(endDate)) {
// All is good...
} else {
// PANIC NOW!!
}
Note. This takes into account the time as well...
If the time is not a factor in your calculations, I tend to move it to either the start of the day or end of the day, depending on what your requirements would be...
public static Date toEndOfDay(Date date) {
Calendar cal = Calendar.getInstance();
cal.setTime(date);
// Move the time to end of the day...
cal.set(Calendar.HOUR_OF_DAY, 23);
cal.set(Calendar.MINUTE, 59);
cal.set(Calendar.MILLISECOND, 999);
return cal.getTime();
}
public static void main(String[] args) {
Calendar cal = Calendar.getInstance();
cal.setTime(startDate);
cal.add(Calendar.MONTH, duration);
Date endDate = toEndOfDay(cal.getTime());
Date today = toEndOfDay(new Date());
// You also want to check for today.equals(endDate)
if (today.before(endDate)) {
// All is good...
} else {
// PANIC NOW!!
}
}