Here you can find the source of dateDiff(Date date1, Date date2)
Parameter | Description |
---|---|
date1 | a parameter |
date2 | a parameter |
public static int dateDiff(Date date1, Date date2)
//package com.java2s; import java.util.Calendar; import java.util.Date; public class Main { /**/*from www. ja v a 2 s .c o m*/ * Returns the difference in days between date1 and date2 * @param date1 * @param date2 * @return int */ public static int dateDiff(Date date1, Date date2) { Calendar cal1 = Calendar.getInstance(); Calendar cal2 = Calendar.getInstance(); cal1.setTime(date1); cal2.setTime(date2); int diff = 0; while (cal1.before(cal2)) { cal1.add(Calendar.DATE, 1); diff++; } return diff; } }