Here you can find the source of compare(Date date1, Date date2, String format)
public static int compare(Date date1, Date date2, String format)
//package com.java2s; import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static int compare(Date date1, Date date2, String format) { if (date1 == null && date2 == null) { return 0; }//from w w w. j a va 2 s .c o m if (date1 == null) { return -1; } if (date2 == null) { return 1; } String strDate1 = format(date1, format); String strDate2 = format(date2, format); return strDate1.compareTo(strDate2); } public static String format(Date date, String format) { return date != null ? new SimpleDateFormat(format).format(date).toString() : ""; } }