Here you can find the source of compareTime(final Calendar firstCal, final Calendar secondCal)
public static int compareTime(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 compareTime(final Calendar firstCal, final Calendar secondCal) { int result = 0; {/* www . j av a 2 s .co m*/ { System.out.println("Calendar.AM_PM = 0, so comparing HOUR_OF_DAY"); System.out.println("firstCal HOUR_OF_DAY " + firstCal.get(Calendar.HOUR_OF_DAY)); System.out.println("secondCal HOUR_OF_DAY " + secondCal.get(Calendar.HOUR_OF_DAY)); if (firstCal.get(Calendar.HOUR_OF_DAY) > secondCal.get(Calendar.HOUR_OF_DAY)) result = 1; else if (firstCal.get(Calendar.HOUR_OF_DAY) < secondCal.get(Calendar.HOUR_OF_DAY)) result = -1; } if (result == 0) { System.out.println("Calendar HOURS are equal so , comparing MINUTES"); System.out.println("firstCal MINUTE " + firstCal.get(Calendar.MINUTE)); System.out.println("secondCal MINUTE" + secondCal.get(Calendar.MINUTE)); if (firstCal.get(Calendar.MINUTE) > secondCal.get(Calendar.MINUTE)) result = 1; else if (firstCal.get(Calendar.MINUTE) < secondCal.get(Calendar.MINUTE)) result = -1; if (result == 0) { System.out.println("Calendar MINUTES are equal so , comparing SECOND"); System.out.println("firstCal SECOND " + firstCal.get(Calendar.SECOND)); System.out.println("secondCal SECOND" + secondCal.get(Calendar.SECOND)); if (firstCal.get(Calendar.SECOND) > secondCal.get(Calendar.SECOND)) result = 1; else if (firstCal.get(Calendar.SECOND) < secondCal.get(Calendar.SECOND)) result = -1; if (result == 0) { System.out.println("Calendar SECONDS are equal so , comparing MILLI SECOND"); if (firstCal.get(Calendar.MILLISECOND) > secondCal.get(Calendar.MILLISECOND)) result = 1; else if (firstCal.get(Calendar.MILLISECOND) < secondCal.get(Calendar.MILLISECOND)) result = -1; } } } } if (result == 1) System.out.println("first date is greater than the second"); else if (result == -1) System.out.println("second date is greater than the first"); else if (result == 0) System.out.println("both the first & second dates are equal"); return result; } }