Here you can find the source of getDaysFrom2Dates(Calendar calendar1, Calendar calendar2)
public static int getDaysFrom2Dates(Calendar calendar1, Calendar calendar2)
//package com.java2s; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class Main { private static final String PATTERN = "yyyy-MM-dd"; private static final Long MILLISECOND_DAY = 86400000L; public static int getDaysFrom2Dates(Calendar calendar1, Calendar calendar2) { return (int) (Math.abs(calendar1.getTimeInMillis() - calendar2.getTimeInMillis()) / MILLISECOND_DAY); }//ww w. j a v a 2s.c o m public static int getDaysFrom2Dates(Date date1, Date date2) { return (int) (Math.abs(date1.getTime() - date2.getTime()) / MILLISECOND_DAY); } public static int getDaysFrom2Dates(String date1, String date2, String pattern) throws ParseException { return getDaysFrom2Dates(parseString2Date(date1, pattern), parseString2Date(date2, pattern)); } public static int getDaysFrom2Dates(String date1, String date2) throws ParseException { return getDaysFrom2Dates(date1, date2, null); } public static Date parseString2Date(String date, String pattern) throws ParseException { return getSimpleDateFormatInstance(pattern).parse(date); } public static Date parseString2Date(String date) throws ParseException { return parseString2Date(date, null); } private static SimpleDateFormat getSimpleDateFormatInstance(String pattern) { return new SimpleDateFormat(pattern == null ? PATTERN : pattern); } }