Java Date Equal equalDates(Date first, Date second)

Here you can find the source of equalDates(Date first, Date second)

Description

Checks if year, month, date of two Date objects match.

License

Creative Commons License

Parameter

Parameter Description
first a parameter
second a parameter

Declaration

public static boolean equalDates(Date first, Date second) 

Method Source Code


//package com.java2s;
//License from project: Creative Commons License 

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

public class Main {
    /**//  w  ww.j  a  va 2 s .c  o  m
     * Checks if year, month, date of two <code>Date</code> objects match.
     * @param first
     * @param second
     * @return
     */
    public static boolean equalDates(Date first, Date second) {
        Calendar calFirst = Calendar.getInstance();
        Calendar calSecond = Calendar.getInstance();

        calFirst.setTime(first);
        calSecond.setTime(second);

        return calFirst.get(Calendar.YEAR) == calSecond.get(Calendar.YEAR)
                && calFirst.get(Calendar.MONTH) == calSecond.get(Calendar.MONTH)
                && calFirst.get(Calendar.DAY_OF_MONTH) == calSecond.get(Calendar.DAY_OF_MONTH);
    }
}

Related

  1. areEqual(Date date1, Date date2)
  2. dateEquals(Date dtFirst, Date dtSecond)
  3. datesEqualToSecond(Date date1, Date date2)
  4. equal(Date date, Date other)
  5. equalDateByDay(Date date1, Date date2)
  6. equalsIgnoreTime(final Date d1, final Date d2)
  7. equalsToDate(Date date1, Date date2, boolean checkTime)
  8. equalsWoTime(final Date date1, final Date date2)
  9. firstLessOrEqualSecond(Date firstDate, Date secondDate)