Java Date Compare by Day isSameDay(Date date1, Date date2)

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

Description

is Same Day

License

Open Source License

Declaration

public static boolean isSameDay(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 {
    public static boolean isSameDay(Date date1, Date date2) {
        if (date1 == null && date2 == null)
            return true;
        if (date1 == null || date2 == null)
            return false;
        Calendar cal1 = GregorianCalendar.getInstance();
        cal1.setTime(date1);/*  w w  w .j a  va2  s  . c  o  m*/
        Calendar cal2 = GregorianCalendar.getInstance();
        cal2.setTime(date2);

        return (cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR))
                && (cal1.get(Calendar.MONTH) == cal2.get(Calendar.MONTH)
                        && (cal1.get(Calendar.DATE) == cal2.get(Calendar.DATE)));
    }
}

Related

  1. isSameDay(Date d1, Date d2)
  2. isSameDay(Date d1, Date d2)
  3. isSameDay(Date d1, Date d2)
  4. isSameDay(Date date)
  5. isSameDay(Date date1, Date date2)
  6. isSameDay(Date date1, Date date2)
  7. isSameDay(Date day1, Date day2)
  8. isSameDay(Date lastUpgradeTime)
  9. isSameDay(final Date date1, final Date date2)