Java Date After afterDay(final Date date1, final Date date2)

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

Description

Get date one day after specified one.

License

Open Source License

Parameter

Parameter Description
date1 Date 1
date2 Date 2

Return

true if after day

Declaration

public static boolean afterDay(final Date date1, final Date date2) 

Method Source Code

//package com.java2s;

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

public class Main {
    /**/*ww  w  .j  a v  a2s  .  c  om*/
     * milliseconds in a second.
     */
    public static final long SECOND = 1000;
    /**
     * milliseconds in a minute.
     */
    public static final long MINUTE = SECOND * 60;

    /**
     * Get date one day after specified one.
     * 
     * @param date1
     *            Date 1
     * @param date2
     *            Date 2
     * @return true if after day
     */
    public static boolean afterDay(final Date date1, final Date date2) {
        if (date1 == null)
            return false;
        return getStartOfDate(date1).after(getStartOfDate(date2));
    }

    /**
     * Get start of date.
     * 
     * @param date
     * @see Date
     * @return the start of date
     */
    public static Date getStartOfDate(final Date date) {
        if (date == null)
            return null;
        Calendar cal = GregorianCalendar.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 new Date(cal.getTime().getTime());
    }
}

Related

  1. after(Date point, Date when)
  2. afterMonth(Date dateTime)
  3. afterOneDay(Date depdt)
  4. dateAfter(Date date, int years, int months)
  5. dateAfter(Date origDate, int amount, int timeUnit)