I want to compare the date part of two java.util.Date
objects. How can I achieve this? I am not looking to comparing the date, month and year separately.
Thanks in advance!
The commons-lang DateUtils provide a nice solution for this problem:
With this you can compare two Date
instances in a single line, loosing sight of every part of the Date
you want.
Date date1 = new Date(2011, 8, 30, 13, 42, 15);
Date date2 = new Date(2011, 8, 30, 15, 23, 46);
int compareTo = DateUtils.truncatedCompareTo(date1, date2,
Calendar.DAY_OF_MONTH);
In this example the value of compareTo
is 0.