Here you can find the source of compareCalendar(Calendar cal1, Calendar cal2)
Parameter | Description |
---|---|
cal1 | first calendar |
cal2 | second calendar |
public static int compareCalendar(Calendar cal1, Calendar cal2)
//package com.java2s; //License from project: Open Source License import java.util.Calendar; public class Main { public final static int DATE1_BEFORE_DATE2 = -1; public final static int DATE1_AFTER_DATE2 = 1; public final static int DATE1_EQUAL_DATE2 = 0; /**/*from www . j a v a2s . c o m*/ * Compare two calendars without time comparison * @param cal1 first calendar * @param cal2 second calendar * @return DATE1_EQUAL_DATE2 if the dates are the same, DATE1_BEFORE_DATE2 if the date1 is before date2 and DATE1_AFTER_DATE2 otherwise */ public static int compareCalendar(Calendar cal1, Calendar cal2) { if (cal1 == null || cal2 == null) { return 0; } if (cal1.get(Calendar.ERA) == cal2.get(Calendar.ERA) && cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR) && cal1.get(Calendar.DAY_OF_YEAR) == cal2.get(Calendar.DAY_OF_YEAR)) { return DATE1_EQUAL_DATE2; } if (cal1.get(Calendar.ERA) < cal2.get(Calendar.ERA) || cal1.get(Calendar.YEAR) < cal2.get(Calendar.YEAR) || cal1.get(Calendar.DAY_OF_YEAR) < cal2.get(Calendar.DAY_OF_YEAR)) { return DATE1_BEFORE_DATE2; } return DATE1_AFTER_DATE2; } }