Here you can find the source of compareDay(Date date, Date anotherDate)
public static int compareDay(Date date, Date anotherDate)
//package com.java2s; import java.util.Calendar; import java.util.Date; public class Main { public static int compareDay(Date date, Date anotherDate) { if (null == date && null == anotherDate) { return 0; }//from w w w . j a va 2 s . c om if (date == null) { date = new Date(); } if (anotherDate == null) { anotherDate = new Date(); } Calendar cal1 = Calendar.getInstance(); Calendar cal2 = Calendar.getInstance(); cal1.setTime(date); cal2.setTime(anotherDate); int year1 = cal1.get(Calendar.YEAR); int year2 = cal2.get(Calendar.YEAR); int month1 = cal1.get(Calendar.MONTH) + 1; int month2 = cal2.get(Calendar.MONTH) + 1; int day1 = cal1.get(Calendar.DAY_OF_YEAR); int day2 = cal2.get(Calendar.DAY_OF_YEAR); if (year1 == year2 && month1 == month2 && day1 == day2) { return 0; } else { if (year1 > year2) { return 1; } else if (month1 > month2) { return 1; } else if (day1 > day2) { return 1; } else { return -1; } } } }