Java tutorial
//package com.java2s; import java.util.Calendar; public class Main { /** * returns 1 if calendar1 > calendar2 0 if calendar1 = calendar2 (same day, * month and year) -1 if calendar1 > calendar2 * * @param calendar1 * @param calendar2 */ public static byte compareDay(Calendar calendar1, Calendar calendar2) { byte dayBefore = 0; int findDiff = 0;// dayBefore = compareMonth(calendar1, calendar2); if (dayBefore == 0) { findDiff = calendar1.get(Calendar.DAY_OF_MONTH) - calendar2.get(Calendar.DAY_OF_MONTH); if (findDiff > 0) { dayBefore = 1; } else if (findDiff < 0) { dayBefore = -1; } else { dayBefore = 0; } } return dayBefore; } /** * returns 1 if calendar1 > calendar2 0 if calendar1 = calendar2 (same month * and year) -1 if calendar1 > calendar2 * * @param calendar1 * @param calendar2 */ public static byte compareMonth(Calendar calendar1, Calendar calendar2) { byte dayBefore = 0; int findDiff = calendar1.get(Calendar.YEAR) - calendar2.get(Calendar.YEAR); if (findDiff > 0) { dayBefore = 1; } else if (findDiff < 0) { dayBefore = -1; } else { findDiff = calendar1.get(Calendar.MONTH) - calendar2.get(Calendar.MONTH); if (findDiff > 0) { dayBefore = 1; } else if (findDiff < 0) { dayBefore = -1; } else { dayBefore = 0; } } return dayBefore; } }