Java Date Between daysBetween2Dates(Date startDate, Date endDate)

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

Description

days Between Dates

License

Open Source License

Declaration

public static long daysBetween2Dates(Date startDate, Date endDate) 

Method Source Code

//package com.java2s;
// distribute, sublicense, and/or sell copies of the Software, and to

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

public class Main {
    public static long daysBetween2Dates(Date startDate, Date endDate) {

        Calendar startDateCal = Calendar.getInstance();
        startDateCal.setTime(startDate);
        startDateCal.set(Calendar.HOUR, 0);
        startDateCal.set(Calendar.MINUTE, 0);
        startDateCal.set(Calendar.SECOND, 0);
        startDateCal.set(Calendar.MILLISECOND, 0);

        Calendar endDateCal = Calendar.getInstance();
        endDateCal.setTime(endDate);//from   w  ww. j av  a 2s.c  om
        endDateCal.set(Calendar.HOUR, 0);
        endDateCal.set(Calendar.MINUTE, 0);
        endDateCal.set(Calendar.SECOND, 0);
        endDateCal.set(Calendar.MILLISECOND, 0);

        return (startDateCal.getTime().getTime() - endDateCal.getTime().getTime()) / (24 * 3600 * 1000);
    }
}

Related

  1. daysBetween(String from, String to, String form)
  2. daysBetween(String from, String to, String format)
  3. daysBetween(String from, String to, String format)
  4. daysBetween(String smdate, String bdate)
  5. daysBetween2Dates(Date d1, Date d2)
  6. daysBetweenCalendars(Calendar date1, Calendar date2)
  7. daysBetweenDate(Integer startDate, Integer endDate)
  8. daysBetweenDates(Date beginDate, Date endDate)
  9. daysBetweenMidnight(final Date startDate, final Date endDate)