Here you can find the source of compareDate(Date date1, Date date2, String pattern)
public static int compareDate(Date date1, Date date2, String pattern)
//package com.java2s; import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static final String DEFAULT_DATE_FORMAT = "yyyy-MM-dd"; public static int compareDate(Date date1, Date date2, String pattern) { String d1 = date2Str(date1, pattern); String d2 = date2Str(date2, pattern); return d1.compareTo(d2); }/*from ww w. ja v a2 s . co m*/ public static String date2Str(Date date, String pattern) { if (null == date) { return null; } if (null == pattern) { pattern = DEFAULT_DATE_FORMAT; } SimpleDateFormat format = new SimpleDateFormat(); format.applyPattern(pattern); return format.format(date); } }