Here you can find the source of daysBetween2Dates(Date d1, Date d2)
Parameter | Description |
---|---|
d1 | From date |
d2 | To Date |
public static long daysBetween2Dates(Date d1, Date d2)
//package com.java2s; import java.util.Calendar; import java.util.Date; public class Main { /**//www . j a v a2 s . c o m * Find out the distance between two dates * @param d1 From date * @param d2 To Date * @return no of days difference between two days. */ public static long daysBetween2Dates(Date d1, Date d2) { Calendar c1 = Calendar.getInstance(); //new GregorianCalendar(); Calendar c2 = Calendar.getInstance(); //new GregorianCalendar(); c1.setTime(d1); c2.setTime(d2); return (c2.getTime().getTime() - c1.getTime().getTime()) / (24 * 3600 * 1000); } }