Here you can find the source of compareDate(Date date1, Date date2)
public static int compareDate(Date date1, Date date2)
//package com.java2s; import java.util.Calendar; import java.util.Date; public class Main { public static int compareDate(Date date1, Date date2) { Calendar calendar1 = Calendar.getInstance(); Calendar calendar2 = Calendar.getInstance(); calendar1.setTime(date1);/*from ww w. java 2 s . co m*/ calendar2.setTime(date2); calendar1.set(Calendar.SECOND, 0); calendar2.set(Calendar.SECOND, 0); calendar1.set(Calendar.MILLISECOND, 0); calendar2.set(Calendar.MILLISECOND, 0); long diff = calendar1.getTimeInMillis() - calendar2.getTimeInMillis(); int minute = (int) (diff / (1000 * 60)); if (minute > 0) { return 1; } else if (minute == 0) { return 0; } return -1; } }