public static int compare ( Date d1 , Date d2 ) { Calendar c1 = Calendar . getInstance ( ) ; c1 . setTime ( d1 ) ; Calendar c2 = Calendar . getInstance ( ) ; c2 . setTime ( d2 ) ; if ( c1 . get ( Calendar . YEAR ) == c2 . get ( Calendar . YEAR ) ) { if ( c1 . get ( Calendar . MONTH ) == c2 . get ( Calendar . MONTH ) ) { return c1 . get ( Calendar . DAY_OF_MONTH ) - c2 . get ( Calendar . DAY_OF_MONTH ) ; } return c1 . get ( Calendar . MONTH ) - c2 . get ( Calendar . MONTH ) ; } return c1 . get ( Calendar . YEAR ) - c2 . get ( Calendar . YEAR ) ; }
Compares two dates taking into consideration only the year month and day