Here you can find the source of dateDiffInDaysIgnoreTime(Date dateStart, Date dateEnd)
public static float dateDiffInDaysIgnoreTime(Date dateStart, Date dateEnd)
//package com.java2s; //License from project: Apache License import java.util.*; public class Main { public static final long ONE_DAY_IN_MILLIS = 60 * 60 * 24 * 1000; public static float dateDiffInDaysIgnoreTime(Date dateStart, Date dateEnd) { return dateDiffInDays(getMidnight(dateStart), getMidnight(dateEnd)); }//from w ww. j a v a2 s. c o m /** * computes (dateEnd - dateStart) in days * @param dateStart the beginning of the intervalle * @param dateEnd the end of the inervalle * @return the length of the intervalle in days */ public static float dateDiffInDays(Date dateStart, Date dateEnd) { return ((float) (dateEnd.getTime() - dateStart.getTime())) / ONE_DAY_IN_MILLIS; } /** * @param date a date * @return a new date with same day, month and year as <code>date</code>, * but with hours, minutes and seconds set to zero. */ public static Date getMidnight(Date date) { if (date == null) throw new IllegalArgumentException("'date' was null"); Calendar c = Calendar.getInstance(); c.setTime(date); c.set(Calendar.HOUR_OF_DAY, 0); c.set(Calendar.MINUTE, 0); c.set(Calendar.SECOND, 0); c.set(Calendar.MILLISECOND, 0); return c.getTime(); } }