Java Date After getAfterDayNumber(Date endDate, Date startDate)

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

Description

get After Day Number

License

Open Source License

Declaration

public static int getAfterDayNumber(Date endDate, Date startDate) 

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 int getAfterDayNumber(Date endDate, Date startDate) {
        Calendar cal = new GregorianCalendar();

        cal.setTime(endDate);//from   w  w  w .j  a v  a 2 s .  co  m
        cal.set(Calendar.HOUR_OF_DAY,
                cal.getActualMinimum(Calendar.HOUR_OF_DAY));
        cal.set(Calendar.MINUTE, cal.getActualMinimum(Calendar.MINUTE));
        cal.set(Calendar.SECOND, cal.getActualMinimum(Calendar.SECOND));
        cal.set(Calendar.MILLISECOND,
                cal.getActualMinimum(Calendar.MILLISECOND));
        Long date1 = cal.getTimeInMillis();

        cal.setTime(startDate);
        cal.set(Calendar.HOUR_OF_DAY,
                cal.getActualMinimum(Calendar.HOUR_OF_DAY));
        cal.set(Calendar.MINUTE, cal.getActualMinimum(Calendar.MINUTE));
        cal.set(Calendar.SECOND, cal.getActualMinimum(Calendar.SECOND));
        cal.set(Calendar.MILLISECOND,
                cal.getActualMinimum(Calendar.MILLISECOND));
        Long date2 = cal.getTimeInMillis();

        return (int) Math.floor((date1 - date2) / (24 * 3600 * 1000));
    }
}

Related

  1. dateAfterNMonths(Date dt, int n)
  2. daysAfter(Date dateInst, int numDays)
  3. getAfter(Date comparedDate, int cursor, String unit)
  4. getAfterDay(Date date, int afterDays)
  5. getAfterDay(Date date, Integer day)
  6. getAfterEndDate(Integer day)
  7. getAfterMin(Date date, int min)
  8. getDateAfter(Date d, int day)
  9. getDateAfter(Date date, int days)