Android Utililty Methods Calendar Interval Get

List of utility methods to do Calendar Interval Get

Description

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

Method

Calendarbefore(Calendar c, long offset)
before
Calendar calendar = null;
if (c != null) {
    calendar = c;
} else {
    calendar = Calendar.getInstance();
calendar.setTimeInMillis(calendar.getTimeInMillis() - offset);
return calendar;
...
intdaysBetween(Calendar startDate, Calendar endDate)
days Between
boolean negative = false;
if (startDate.after(endDate)) {
    Calendar c = startDate;
    startDate = endDate;
    endDate = c;
    negative = true;
int MILLIS_IN_DAY = 1000 * 60 * 60 * 24;
...
intyearsBetweenDates(Calendar from, Calendar to)
years Between Dates
if (from.after(to)) {
    Calendar temp = to;
    to = from;
    from = temp;
int years = to.get(Calendar.YEAR) - from.get(Calendar.YEAR);
if (years != 0) {
    int fromSpan = (from.get(Calendar.MONTH) + 1) * 100
...
longgetExactDiff(final Calendar cal1, final Calendar cal2)
get Exact Diff
long diff = 0L;
if (cal1.before(cal2)) {
    long start = cal1.getTimeInMillis();
    long end = cal2.getTimeInMillis();
    diff = end - start;
    diff = diff / (1000 * 60 * 60 * 24);
} else if (cal1.after(cal2)) {
    diff = getExactDiff(cal2, cal1);
...