Java Date Compare by Day isSameDay(Date d1, Date d2)

Here you can find the source of isSameDay(Date d1, Date d2)

Description

is Same Day

License

Apache License

Declaration

public static boolean isSameDay(Date d1, Date d2) 

Method Source Code


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

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

public class Main {
    public static boolean isSameDay(Date d1, Date d2) {
        return getDateWithoutTimePart(d1).compareTo(getDateWithoutTimePart(d2)) == 0;
    }/*from   w  w  w.j a  v a  2 s  . c  om*/

    public static Date getDateWithoutTimePart(Date date) {

        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);
        return cal.getTime();

    }
}

Related

  1. isSameDay(Date a, Date b)
  2. isSameDay(Date a, Date b)
  3. isSameDay(Date d1, Date d2)
  4. isSameDay(Date d1, Date d2)
  5. isSameDay(Date date)
  6. isSameDay(Date date1, Date date2)
  7. isSameDay(Date date1, Date date2)
  8. isSameDay(Date date1, Date date2)