So for an assignment we HAVE to use the JDK Date or Calendar objects to represent dates in the system we are designing (otherwise I'd be using another library). For a function I need to make sure that at least a certain number of years has passed since the input date to the present date. I wrote the following method to try and calculate the days between two Calendar objects:
public static int daysSince(Calendar pastDate) {
Calendar presentDate = Calendar.getInstance();
int daysSince = 0;
while (pastDate.before(presentDate)) {
pastDate.add(Calendar.DAY_OF_MONTH, 1);
daysSince++;
} return daysSince;
}
However, this method always seems to return exactly 30 days less than the actual number of days between the two dates, and I can't seem to figure out why? For example, it says there is only one day between 3/25/2016 and 4/25/2016. What am I missing?