Here you can find the source of compare(Date date1, Date date2)
public static int compare(Date date1, Date date2)
//package com.java2s; import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static final String VN_DATE_FORMAT = "dd/MM/yyyy"; public static int compare(Date date1, Date date2) { String d1 = dateToString(date1, "yyyyMMdd"); String d2 = dateToString(date2, "yyyyMMdd"); return d1.compareTo(d2); }/*from w ww. j av a 2s . co m*/ public static String dateToString(Date date, String format) { if (format == null) format = VN_DATE_FORMAT; SimpleDateFormat ts = new SimpleDateFormat(format); return ts.format(date); } }