Java Day End todayOnOrBetween(Date startDate, Date endDate)

Here you can find the source of todayOnOrBetween(Date startDate, Date endDate)

Description

today On Or Between

License

Open Source License

Parameter

Parameter Description
startDelegation a parameter
endDelegation a parameter

Declaration

public static boolean todayOnOrBetween(Date startDate, Date endDate) 

Method Source Code

//package com.java2s;

import java.util.Calendar;

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

public class Main {
    /**/*from   w  w w . ja v a 2  s.  c  om*/
     * @param startDelegation
     * @param endDelegation
     * @return
     */
    public static boolean todayOnOrBetween(Date startDate, Date endDate) {

        Date today = new Date();
        if ((isSameDate(today, startDate)
                || today.after(startDate) && (isSameDate(today, endDate) || today.before(endDate)))) {
            return true;
        }
        return false;
    }

    /**
     * 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. setTimeToEndofDay(Calendar calendar)
  2. setTimeToEndOfDay(Date date)
  3. subtractSecond(Date startDate, Date endDate)
  4. toDayEnds(Date date)
  5. toDayInterval(Date startDate, Date endDate)
  6. yearsBetween(final Date startDate, final Date endDate)