Here you can find the source of compareDates(Date date1, Date date2)
public static int compareDates(Date date1, Date date2)
//package com.java2s; //License from project: Open Source License import java.sql.Timestamp; import java.util.Date; public class Main { /**//from w w w . ja v a 2 s . com * Equivalent of compareTo() but actually works because Sun * fucked up the JDK. See: * * http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5103041 * http://forum.hibernate.org/viewtopic.php?t=959124 * http://forum.hibernate.org/viewtopic.php?t=925275 * http://forum.hibernate.org/viewtopic.php?t=927602 */ public static int compareDates(Date date1, Date date2) { if (date1 instanceof Timestamp) { if (date2 instanceof Timestamp) { return date1.compareTo(date2); } else { return date1.compareTo(new Timestamp(date2.getTime())); } } else { if (date2 instanceof Timestamp) { return new Timestamp(date1.getTime()).compareTo(date2); } else { return date1.compareTo(date2); } } } }