For calculating days between two dates(Date or Calendar object) consider the end date also for calculation.
I used below method:
public static int daysBetween(Date d1, Date d2) {
return Days.daysBetween( new LocalDate(d1.getTime()), new LocalDate(d2.getTime())).getDays();
}
For example
Date d1 = new Date(); // 30-08-2016
Calendar c= Calendar.getInstance();
c.add(Calendar.YEAR, 2016);
c.add(Calendar.MONTH, Calendar.AUGUST);
c.add(Calendar.DAY_OF_MONTH, 31)// 31-08-2016
Date d2 = c.getTime();
daysBetween(d2, d1);
The method returns '1' but I want as '2' because I need to consider end date also it means 30 and 31.
For that requirement i can add the +1 whatever that method returns or before returning the value also. This is not a correct way to solve the problem and need to consider leap year dates also.
Please help me resolve the problem.