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: Open Source License import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static int compareDate(Date date1, Date date2) { long due = date1.getTime() + 0 * 24 * 60 * 60 * 1000; long due2 = date2.getTime() + 0 * 24 * 60 * 60 * 1000; if (due == due2) { return 0; } else if (due > due2) { return 1; } else/*from www . j a v a 2s . c om*/ return -1; } public static String getTime(Date dt, String format) { SimpleDateFormat st = new SimpleDateFormat(format); return st.format(dt); } }