Вы можете сравнить значение по значению, как это
d1.getDate().equals(d2.getDate()) &&
d1.getYear().equals(d2.getYear()) &&
d1.getMonth().equals(d2.getMonth())
Или
Date date1 = new Date(d1.getYear(), d1.getMonth(), d1.getDate());
Date date2 = new Date(d2.getYear(), d2.getMonth(), d2.getDate());
date1.compareTo(date2);
Если вы работаете с классом Date, рассмотрите возможность использования класса Calendar вместо
Вот самое элегантное решение, использующее Календарь и Компаратор для этого
public class CalendarDateWithoutTimeComparator implements Comparator<Calendar> {
public int compare(Calendar cal1, Calendar cal2) {
if(cal1.get(Calendar.YEAR) != cal2.get(Calendar.YEAR)) {
return cal1.get(Calendar.YEAR) - cal2.get(Calendar.YEAR);
} else if (cal1.get(Calendar.MONTH) != cal2.get(Calendar.MONTH)) {
return cal1.get(Calendar.MONTH) - cal2.get(Calendar.MONTH);
}
return cal1.get(Calendar.DAY_OF_MONTH) - cal2.get(Calendar.DAY_OF_MONTH);
}
}
Использование:
Calendar c1 = Calendar.getInstance();
Calendar c2 = Calendar.getInstance();
// these calendars are equal
CalendarDateWithoutTimeComparator comparator = new CalendarDateWithoutTimeComparator();
System.out.println(comparator.compare(c1, c2));
List<Calendar> list = new ArrayList<Calendar>();
list.add(c1);
list.add(c2);
Collections.sort(list, comparator);