List of utility methods to do Calendar Compare
boolean | isEqual(Calendar calendar, Date date) Returns true if the month day and year for the calendar and date object are the same. if (calendar == null && date == null) { return true; if (calendar == null || date == null) { return false; Calendar calendarValueForDateVariable = Calendar.getInstance(); calendarValueForDateVariable.setTime(date); ... |
boolean | isEquals(Calendar sourceDate, Calendar compareDate) is Equals boolean check = false; if ((sourceDate.get(Calendar.DATE) == compareDate.get(Calendar.DATE)) && (sourceDate.get(Calendar.MONTH) == compareDate.get(Calendar.MONTH)) && (sourceDate.get(Calendar.YEAR) == compareDate.get(Calendar.YEAR))) { check = true; return check; |
boolean | isSameDate(Calendar d1, Calendar d2) Returns whether the input dates are on the same date. return d1.get(Calendar.YEAR) == d2.get(Calendar.YEAR)
&& d1.get(Calendar.DAY_OF_YEAR) == d2.get(Calendar.DAY_OF_YEAR);
|
boolean | isSameDate(java.util.Calendar date1, java.util.Calendar date2) is Same Date return (date1.get(java.util.Calendar.DATE) == date2.get(java.util.Calendar.DATE)
&& date1.get(java.util.Calendar.MONTH) == date2.get(java.util.Calendar.MONTH)
&& date1.get(java.util.Calendar.YEAR) == date2.get(java.util.Calendar.YEAR));
|
boolean | isSameInstant(Calendar cal1, Calendar cal2) Checks if two calendar objects represent the same instant in time. if (cal1 == null || cal2 == null) { throw new IllegalArgumentException("The date must not be null"); return cal1.getTime().getTime() == cal2.getTime().getTime(); |
boolean | isSameInstant(Calendar cal1, Calendar cal2) is Same Instant if (cal1 == null || cal2 == null) { throw new IllegalArgumentException("The date must not be null"); return cal1.getTime().getTime() == cal2.getTime().getTime(); |
boolean | isSameInstant(Calendar cal1, Calendar cal2) Checks if two calendar objects represent the same instant in time. This method compares the long millisecond time of the two objects. if (cal1 == null || cal2 == null) { throw new IllegalArgumentException("The date must not be null"); return cal1.getTime().getTime() == cal2.getTime().getTime(); |
boolean | isSameInstant(final Calendar cal1, final Calendar cal2) is Same Instant return cal1.getTime().getTime() == cal2.getTime().getTime();
|
Calendar | max(Calendar cal1, Calendar cal2) max return cal1.after(cal2) ? cal1 : cal2;
|
Calendar | min(Calendar c1, Calendar c2) min Calendar result = Calendar.getInstance();
result.setTimeInMillis(c2.getTimeInMillis());
if (yearsDiff(c1, c2) > 1.0) {
result.set(WEEK_OF_YEAR, 0);
result.set(MONTH, 0);
result.set(DAY_OF_MONTH, 0);
result.set(HOUR_OF_DAY, 0);
result.set(MINUTE, 0);
...
|