Java Date Equal isSameDate(Date date1, Date date2)

Here you can find the source of isSameDate(Date date1, Date date2)

Description

Returns true if the 2 dates are the same, regardless of the time

License

Open Source License

Parameter

Parameter Description
date1 a parameter
date2 a parameter

Declaration

public static boolean isSameDate(Date date1, Date date2) 

Method Source Code

//package com.java2s;

import java.util.Calendar;

import java.util.Date;
import java.util.GregorianCalendar;

public class Main {
    /**// ww  w  . ja v a2 s. c  o m
     * Returns true if the 2 dates are the same, regardless of the time
     * 
     * @param date1
     * @param date2
     * @return
     */
    public static boolean isSameDate(Date date1, Date date2) {
        if (date1 == null || date2 == null) {
            return false;
        }
        Calendar c1 = (GregorianCalendar) Calendar.getInstance();
        c1.setTime(date1);
        c1.set(Calendar.HOUR_OF_DAY, 0);
        c1.set(Calendar.MINUTE, 0);
        c1.set(Calendar.SECOND, 0);
        c1.set(Calendar.MILLISECOND, 0);

        Calendar c2 = (GregorianCalendar) Calendar.getInstance();
        c2.setTime(date2);
        c2.set(Calendar.HOUR_OF_DAY, 0);
        c2.set(Calendar.MINUTE, 0);
        c2.set(Calendar.SECOND, 0);
        c2.set(Calendar.MILLISECOND, 0);

        return c1.equals(c2);
    }
}

Related

  1. isEqualByDay(Date date1, Date date2)
  2. isEqualDate(Date date1, Date date2)
  3. isEqualField(int field, Date d1, Date d2)
  4. isLowerEqualDate(Date date)
  5. isSameDate(Date date, Date date1)
  6. isSameDate(Date pathDate, Date now)
  7. isSameDate(long var0, long var2)
  8. monthEquals(Date current, Date compare)
  9. nowInDateEquals(Date now, Date d1, Date d2)