Here you can find the source of getIntervalDays(Date fDate, Date oDate)
public static int getIntervalDays(Date fDate, Date oDate) throws ParseException
//package com.java2s; //License from project: Open Source License import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static int getIntervalDays(Date fDate, Date oDate) throws ParseException { String fDate1 = toString(fDate, "yyyyMMdd"); String oDate1 = toString(oDate, "yyyyMMdd"); java.text.SimpleDateFormat df = new java.text.SimpleDateFormat("yyyyMMdd"); java.util.Date cDate = df.parse(fDate1); java.util.Date dDate = df.parse(oDate1); return (int) ((cDate.getTime() - dDate.getTime()) / (24 * 60 * 60 * 1000)); }//ww w . jav a2 s. c o m public static String toString(Date date, String format) { if (date != null) { SimpleDateFormat dateformatter = new SimpleDateFormat(format); String dateString = dateformatter.format(date); return dateString; } else { return null; } } }