Compares two dates are equals at day, month and year level, ignoring time
import java.util.Calendar;
public class Main {
public static boolean isDifferentDay(java.util.Date f1, java.util.Date f2) {
if (f1 == null && f2 == null) return false;
if (f1 == null || f2 == null) return true;
Calendar cal = Calendar.getInstance();
cal.setTime(f1);
int dd1 = cal.get(Calendar.DAY_OF_MONTH);
int mm1 = cal.get(Calendar.MONTH);
int aa1 = cal.get(Calendar.YEAR);
cal.setTime(f2);
int dd2 = cal.get(Calendar.DAY_OF_MONTH);
int mm2 = cal.get(Calendar.MONTH);
int aa2 = cal.get(Calendar.YEAR);
return !(aa1==aa2 && mm1==mm2 && dd1==dd2);
}
}
Home
Java Book
Runnable examples
Java Book
Runnable examples
Date Compare:
- Are two calendar objects represent the same local time.
- Are two dates or two calendars the same day
- Is a date the same day with another date
- Is a date after another date
- Is a date before another date
- Is date or calendar today's date
- Is a calendar or date after/before today or within a number of days in the future
- Compare two Date objects using compareTo
- Compares two dates are equals at day, month and year level, ignoring time
- Compare two times equals regardless of the date
- Compare two dates and times for equal
- Compare two Date