Java Calendar Compare isEqual(Calendar calendar, Date date)

Here you can find the source of isEqual(Calendar calendar, Date date)

Description

Returns true if the month day and year for the calendar and date object are the same.

License

Open Source License

Parameter

Parameter Description
calendar The Calendar object.
date The date object.

Declaration

public static boolean isEqual(Calendar calendar, Date date) 

Method Source Code

//package com.java2s;

import java.util.Calendar;
import java.util.Date;

public class Main {
    /**// w  ww.  jav  a 2 s  .c om
     * Returns true if the month day and year for the calendar and date object are the same. 
     * @param calendar The Calendar object.
     * @param date The date object.
     */
    public static boolean isEqual(Calendar calendar, Date date) {
        if (calendar == null && date == null) {
            return true;
        }
        if (calendar == null || date == null) {
            return false;
        }

        Calendar calendarValueForDateVariable = Calendar.getInstance();
        calendarValueForDateVariable.setTime(date);

        return calendarValueForDateVariable.get(Calendar.MONTH) == calendar.get(Calendar.MONTH)
                && calendarValueForDateVariable.get(Calendar.YEAR) == calendar.get(Calendar.YEAR)
                && calendarValueForDateVariable.get(Calendar.DAY_OF_MONTH) == calendar.get(Calendar.DAY_OF_MONTH);

    }
}

Related

  1. compareDates(final Calendar firstCal, final Calendar secondCal)
  2. compareDateTime(final Calendar firstCal, final Calendar secondCal)
  3. compareDay(Calendar calendar, Calendar calendar1)
  4. compareSameDay(Calendar first, Calendar second)
  5. compareTime(final Calendar firstCal, final Calendar secondCal)
  6. isEquals(Calendar sourceDate, Calendar compareDate)
  7. isSameDate(Calendar d1, Calendar d2)
  8. isSameDate(java.util.Calendar date1, java.util.Calendar date2)
  9. isSameInstant(Calendar cal1, Calendar cal2)