Java Calendar Compare isSameDate(Calendar d1, Calendar d2)

Here you can find the source of isSameDate(Calendar d1, Calendar d2)

Description

Returns whether the input dates are on the same date.

License

LGPL

Parameter

Parameter Description
d1 input date 1
d2 input date 2

Return

true if they are on the same date.

Declaration

public static boolean isSameDate(Calendar d1, Calendar d2) 

Method Source Code


//package com.java2s;
//License from project: LGPL 

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

public class Main {
    /**/*w w  w .j a  v a  2 s. c om*/
     * Returns whether the input dates are on the same date.
     * 
     * @param d1
     *            input date 1
     * @param d2
     *            input date 2
     * @return true if they are on the same date.
     */
    public static boolean isSameDate(Calendar d1, Calendar d2) {
        return d1.get(Calendar.YEAR) == d2.get(Calendar.YEAR)
                && d1.get(Calendar.DAY_OF_YEAR) == d2.get(Calendar.DAY_OF_YEAR);
    }

    /**
     * Returns whether the input dates are on the same date.
     * 
     * @param d1
     *            input date 1
     * @param d2
     *            input date 2
     * @return true if they are on the same date.
     */
    public static boolean isSameDate(Date d1, Date d2) {
        Calendar c1 = Calendar.getInstance();
        c1.setTime(d1);

        Calendar c2 = Calendar.getInstance();
        c2.setTime(d2);

        return isSameDate(c1, c2);
    }
}

Related

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