Android Calendar Interval Get getExactDiff(final Calendar cal1, final Calendar cal2)

Here you can find the source of getExactDiff(final Calendar cal1, final Calendar cal2)

Description

get Exact Diff

Declaration

public static final long getExactDiff(final Calendar cal1,
            final Calendar cal2) 

Method Source Code

//package com.java2s;

import java.util.Calendar;

public class Main {
    public static final long getExactDiff(final Calendar cal1,
            final Calendar cal2) {
        long diff = 0L;
        if (cal1.before(cal2)) {
            long start = cal1.getTimeInMillis();
            long end = cal2.getTimeInMillis();
            diff = end - start;//from w  w  w  .  ja  v a2  s. c  om
            diff = diff / (1000 * 60 * 60 * 24);
        } else if (cal1.after(cal2)) {
            diff = getExactDiff(cal2, cal1);
            diff *= -1;
        }
        return diff;
    }
}

Related

  1. before(Calendar c, long offset)
  2. daysBetween(Calendar startDate, Calendar endDate)
  3. yearsBetweenDates(Calendar from, Calendar to)