List of utility methods to do Calendar Different
int | getYearDifference(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; |
long | millisDiff(Calendar c1, Calendar c2) millis Diff long time1 = c1.getTimeInMillis(); long time2 = c2.getTimeInMillis(); return Math.abs(time1 - time2); |
double | minutesDiff(Calendar c1, Calendar c2) minutes Diff return secondsDiff(c1, c2) / 60.0;
|
int | reduceAndCorrect(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 { ... |
long | timeDiff(Calendar c1, Calendar c2) Diffs two Calendar instances (C2 - C1) return (c2.getTimeInMillis() - c1.getTimeInMillis()) / 1000;
|