Here you can find the source of daysBetween(Calendar startTime, Calendar endTime)
public static int daysBetween(Calendar startTime, Calendar endTime)
//package com.java2s; //License from project: Apache License import java.util.Calendar; public class Main { public static int daysBetween(Calendar startTime, Calendar endTime) { if (startTime == null) { throw new IllegalArgumentException("startTime is null"); }// ww w.ja va2s . c o m if (endTime == null) { throw new IllegalArgumentException("endTime is null"); } if (startTime.compareTo(endTime) > 0) { throw new IllegalArgumentException("endTime is before the startTime"); } return (int) ((endTime.getTimeInMillis() - startTime.getTimeInMillis()) / (1000 * 60 * 60 * 24)); } }