Java Date Between daysBetweenDates(Date beginDate, Date endDate)

Here you can find the source of daysBetweenDates(Date beginDate, Date endDate)

Description

days Between Dates

License

Open Source License

Declaration

public static int daysBetweenDates(Date beginDate, Date endDate) 

Method Source Code

//package com.java2s;

import java.util.*;

public class Main {

    public static int daysBetweenDates(Date beginDate, Date endDate) {
        int days = 0;
        Calendar calo = Calendar.getInstance();
        Calendar caln = Calendar.getInstance();
        calo.setTime(beginDate);/*  w  w w . j ava2 s .  c om*/
        caln.setTime(endDate);
        int oday = calo.get(6);
        int nyear = caln.get(1);
        for (int oyear = calo.get(1); nyear > oyear;) {
            calo.set(2, 11);
            calo.set(5, 31);
            days += calo.get(6);
            oyear++;
            calo.set(1, oyear);
        }
        int nday = caln.get(6);
        days = (days + nday) - oday;
        return days;
    }
}

Related

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