Here you can find the source of compareDates(final Calendar firstCal, final Calendar secondCal)
public static int compareDates(final Calendar firstCal, final Calendar secondCal)
//package com.java2s; //License from project: Open Source License import java.util.Calendar; public class Main { public static int compareDates(final Calendar firstCal, final Calendar secondCal) { int result = 0; if (firstCal.get(Calendar.YEAR) > secondCal.get(Calendar.YEAR)) result = 1;//w ww .ja va2 s .c o m else if (firstCal.get(Calendar.YEAR) < secondCal.get(Calendar.YEAR)) result = -1; else { if (firstCal.get(Calendar.MONTH) > secondCal.get(Calendar.MONTH)) result = 1; else if (firstCal.get(Calendar.MONTH) < secondCal.get(Calendar.MONTH)) result = -1; else { if (firstCal.get(Calendar.DATE) > secondCal.get(Calendar.DATE)) result = 1; else if (firstCal.get(Calendar.DATE) < secondCal.get(Calendar.DATE)) result = -1; } } return result; } }