Java Calendar Between getDaysBetween(Calendar start, Calendar end)

Here you can find the source of getDaysBetween(Calendar start, Calendar end)

Description

get Days Between

License

Open Source License

Declaration

public static int getDaysBetween(Calendar start, Calendar end) 

Method Source Code

//package com.java2s;

import java.util.Calendar;

public class Main {

    public static int getDaysBetween(Calendar start, Calendar end) {
        if (start.after(end)) {
            Calendar swap = start;
            start = end;/*from  w  ww .j  a  v  a2s .  c  om*/
            end = swap;
        }
        int days = end.get(Calendar.DAY_OF_YEAR) - start.get(Calendar.DAY_OF_YEAR);
        int y2 = end.get(Calendar.YEAR);
        if (start.get(Calendar.YEAR) != y2) {
            start = (Calendar) start.clone();
            do {
                days += start.getActualMaximum(Calendar.DAY_OF_YEAR);
                start.add(Calendar.YEAR, 1);
            } while (start.get(Calendar.YEAR) != y2);
        }
        return days;
    }
}

Related

  1. daysBetweenForDate(Calendar startDate, Calendar endDate)
  2. daysBetweenxX(Calendar start, Calendar end)
  3. getDaysBetween(Calendar d1, Calendar d2)
  4. getDaysBetween(Calendar d1, Calendar d2)
  5. getDaysBetween(Calendar firstDate, Calendar lastDate)
  6. getDaysBetween(Calendar startDate, Calendar endDate)
  7. getDaysBetween(final Calendar start, final Calendar end)
  8. getFmtCalendar(Calendar c, long betweenTimeout, StringBuilder sb)
  9. hoursBetween(Calendar start, Calendar end, boolean assumeSameDate)