Java Utililty Methods Calendar Different

List of utility methods to do Calendar Different

Description

The list of methods to do Calendar Different are organized into topic(s).

Method

intgetYearDifference(GregorianCalendar fromCalendar, GregorianCalendar toCalendar)
get Year Difference
int count = 0;
for (fromCalendar.add(Calendar.YEAR, 1); fromCalendar.compareTo(toCalendar) <= 0; fromCalendar
        .add(Calendar.YEAR, 1)) {
    count++;
return count;
longmillisDiff(Calendar c1, Calendar c2)
millis Diff
long time1 = c1.getTimeInMillis();
long time2 = c2.getTimeInMillis();
return Math.abs(time1 - time2);
doubleminutesDiff(Calendar c1, Calendar c2)
minutes Diff
return secondsDiff(c1, c2) / 60.0;
intreduceAndCorrect(Calendar start, Calendar end, int field, int difference)
Reduces by difference, then if it overshot, calculates the overshot amount and fixes and returns the amount to change by.
end.add(field, -1 * difference);
int endValue = end.get(field);
int startValue = start.get(field);
if (endValue < startValue) {
    int newdiff = startValue - endValue;
    end.add(field, newdiff);
    return newdiff;
} else {
...
longtimeDiff(Calendar c1, Calendar c2)
Diffs two Calendar instances (C2 - C1)
return (c2.getTimeInMillis() - c1.getTimeInMillis()) / 1000;