Here you can find the source of getDaysBetween(Calendar d1, Calendar d2)
public static int getDaysBetween(Calendar d1, Calendar d2)
//package com.java2s; //License from project: Apache License import java.util.Calendar; public class Main { public static int getDaysBetween(Calendar d1, Calendar d2) { int days = 0; int years = d1.get(Calendar.YEAR) - d2.get(Calendar.YEAR); if (years == 0) { days = d2.get(Calendar.DAY_OF_YEAR) - d1.get(Calendar.DAY_OF_YEAR); return days; } else if (years > 0) { for (int i = 0; i < years; i++) { d2.add(Calendar.YEAR, 1); days += -d2.getActualMaximum(Calendar.DAY_OF_YEAR); if (d1.get(Calendar.YEAR) == d2.get(Calendar.YEAR)) { days += d2.get(Calendar.DAY_OF_YEAR) - d1.get(Calendar.DAY_OF_YEAR); return days; }//w w w .j a va2 s.c o m } } else { for (int i = 0; i < -years; i++) { d1.add(Calendar.YEAR, 1); days += d1.getActualMaximum(Calendar.DAY_OF_YEAR); if (d1.get(Calendar.YEAR) == d2.get(Calendar.YEAR)) { days += d2.get(Calendar.DAY_OF_YEAR) - d1.get(Calendar.DAY_OF_YEAR); return days; } } } return days; } }