Java Date After isInSameDayOrAfter(Date d1, Date d2)

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

Description

is In Same Day Or After

License

Open Source License

Declaration

public static boolean isInSameDayOrAfter(Date d1, Date d2) 

Method Source Code


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

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

public class Main {
    public static boolean isInSameDayOrAfter(Date d1, Date d2) {
        if (d1 == null || d2 == null)
            return false;

        if (isInSameDay(d1, d2) || d1.after(d2))
            return true;
        return false;
    }//ww w . j  a va  2s  . c o m

    /** Returns true if the Dates are in the same day. Ignores time.
     * @param d1 Day one compared to
     * @param d2 Day two
     * @return
     */
    public static boolean isInSameDay(Date d1, Date d2) {
        if (d1 == null || d2 == null) {
            return false;
        }

        GregorianCalendar cal1 = new GregorianCalendar();
        cal1.setTime(d1);
        GregorianCalendar cal2 = new GregorianCalendar();
        cal2.setTime(d2);

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

Related

  1. isAfterForDay(Date date, Date ref)
  2. isAfterHour(Date source, int hour)
  3. isAfterToday(Date dag)
  4. isDateAfter(Date date1, Date date2)
  5. isEqualOrAfterTomorrow(Date d)
  6. isNotAfter(Date sDate, Date eDate)
  7. isTimeAfter(Date time1, Date time2)