Java Date Compare by Day isSameDay(Date day1, Date day2)

Here you can find the source of isSameDay(Date day1, Date day2)

Description

Checks if it is the same day in both dates

License

Open Source License

Parameter

Parameter Description
from a parameter
to a parameter

Declaration

public static boolean isSameDay(Date day1, Date day2) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

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

public class Main {
    /**//from  w  ww . j a  v  a2s.  c  o  m
     * Checks if it is the same day in both dates 
     * @param from
     * @param to
     * @return
     */
    public static boolean isSameDay(Date day1, Date day2) {
        if (day1 == null || day1 == null) {
            throw new IllegalArgumentException("The date must not be null");
        }
        Calendar cal1 = Calendar.getInstance();
        cal1.setTime(day1);
        Calendar cal2 = Calendar.getInstance();
        cal1.setTime(day2);
        return (cal1.get(Calendar.ERA) == cal2.get(Calendar.ERA)
                && cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR)
                && cal1.get(Calendar.DAY_OF_YEAR) == cal2.get(Calendar.DAY_OF_YEAR));
    }
}

Related

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