Here you can find the source of compareTo(Date src, Date dest)
public static int compareTo(Date src, Date dest)
//package com.java2s; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.*; public class Main { public static final String DATETIME_PATTERN = "yyyy-MM-dd HH:mm:ss"; public static int compareTo(Date src, Date dest) { Date d1 = parseDateTime(formatDateTime(src, DATETIME_PATTERN), DATETIME_PATTERN); Date d2 = parseDateTime(formatDateTime(dest, DATETIME_PATTERN), DATETIME_PATTERN); int i = d1.compareTo(d2); return i; }/*from w w w .j a v a2s . c om*/ public static Date parseDateTime(String str) { return parseDateTime(str, DATETIME_PATTERN); } public static Date parseDateTime(String str, String pattern) { Date d = null; SimpleDateFormat sdf = new SimpleDateFormat(pattern); try { d = sdf.parse(str); } catch (ParseException e) { e.printStackTrace(); } return d; } public static String formatDateTime(Date d) { return formatDateTime(d, DATETIME_PATTERN); } public static String formatDateTime(Date d, String pattern) { SimpleDateFormat sdf = new SimpleDateFormat(pattern); return sdf.format(d); } }