I want to compare two Calendar objects to see if they both contain the same date. I don\'t care about any value below days.
I\'ve implemented this and I can\'t think
You can use somehing like DateUtils
public boolean isSameDay(Calendar cal1, Calendar cal2) {
if (cal1 == null || cal2 == null)
return false;
return (cal1.get(Calendar.ERA) == cal2.get(Calendar.ERA)
&& cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR)
&& cal1.get(Calendar.DAY_OF_YEAR) == cal2.get(Calendar.DAY_OF_YEAR));
}
You can also check if is the same date-time:
public boolean isSameDateTime(Calendar cal1, Calendar cal2) {
// compare if is the same ERA, YEAR, DAY, HOUR, MINUTE and SECOND
return (cal1.get(Calendar.ERA) == cal2.get(Calendar.ERA)
&& cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR)
&& cal1.get(Calendar.DAY_OF_YEAR) == cal2.get(Calendar.DAY_OF_YEAR)
&& cal1.get(Calendar.HOUR_OF_DAY) == cal2.get(Calendar.HOUR_OF_DAY)
&& cal1.get(Calendar.MINUTE) == cal2.get(Calendar.MINUTE)
&& cal1.get(Calendar.SECOND) == cal2.get(Calendar.SECOND));
}