Here you can find the source of dayDiff(Date d1, Date d2)
Parameter | Description |
---|---|
d1 | a parameter |
d2 | a parameter |
public static int dayDiff(Date d1, Date d2)
//package com.java2s; //License from project: Open Source License import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; public class Main { /**//from w w w .j av a2 s . c o m * Determines the number of days between two dates * * @param d1 * @param d2 * @return */ public static int dayDiff(Date d1, Date d2) { long timeDiff = removeTime(d1).getTime() - removeTime(d2).getTime(); // milliseconds in 1 day = 86400000 return (int) (timeDiff / 86400000); } /** * Sets the time on the given {@link Date} object to midnight * * @param d * @return */ public static Date removeTime(Date d) { Calendar inst = GregorianCalendar.getInstance(); inst.setTime(d); inst.set(Calendar.HOUR_OF_DAY, 0); inst.set(Calendar.MINUTE, 0); inst.set(Calendar.SECOND, 0); inst.set(Calendar.MILLISECOND, 0); return inst.getTime(); } }