Possible Duplicate:
How to compare two Dates without the time portion?
How to compare date without time in java ?
Date currentDate = new Date();// get current date
Date eventDate = tempAppointments.get(i).mStartDate;
int dateMargin = currentDate.compareTo(eventDate);
this code compares time and date !
Write your own method which does not take the time into account:
Note that methods
getYear()
,getMonth()
andgetDate()
have been deprecated. You should go through theCalendar
class and perform the same method.You can write a method
Date withoutTime(Date)
that returns a copy of the date in which all time fields (hour, minute, second, milli) are set to zero. Then you can compare these.Or you can switch to Joda Time if possible. That library already has the data type
DateMidnight
, which is what you are looking for.Use truncate function: http://commons.apache.org/lang/api-2.5/org/apache/commons/lang/time/DateUtils.html
Try compare dates changing to 00:00:00 its time (as this function do):