Here you can find the source of compareDate(Date date1, Date date2)
public static int compareDate(Date date1, Date date2)
//package com.java2s; //License from project: Apache License import java.util.Calendar; import java.util.Date; public class Main { public static int compareDate(Date date1, Date date2) { Calendar c1 = Calendar.getInstance(); c1.setTime(date1);/*from w w w . j av a 2 s. com*/ Calendar c2 = Calendar.getInstance(); c2.setTime(date2); if (c1.get(Calendar.YEAR) != c2.get(Calendar.YEAR)) return c1.get(Calendar.YEAR) - c2.get(Calendar.YEAR); if (c1.get(Calendar.MONTH) != c2.get(Calendar.MONTH)) return c1.get(Calendar.MONTH) - c2.get(Calendar.MONTH); return c1.get(Calendar.DAY_OF_MONTH) - c2.get(Calendar.DAY_OF_MONTH); } }