Java Day Between getDaysBetweenDate(Date begin, Date end)

Here you can find the source of getDaysBetweenDate(Date begin, Date end)

Description

get Days Between Date

License

Apache License

Declaration

public static int getDaysBetweenDate(Date begin, Date end) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

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

public class Main {
    public static int getDaysBetweenDate(Date begin, Date end) {
        int bDay = getDateField(begin, Calendar.DAY_OF_YEAR);
        int eDay = getDateField(end, Calendar.DAY_OF_YEAR);
        return eDay - bDay;
    }/*  ww  w  .ja  va  2 s.c  o m*/

    private static int getDateField(Date date, int field) {
        Calendar c = getCalendar();
        c.setTime(date);
        return c.get(field);
    }

    private static Calendar getCalendar() {
        return Calendar.getInstance();
    }

    public static int get(int field, Date date) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        return c.get(field);
    }
}

Related

  1. getDaysBetween(Date date1, Date date2)
  2. getDaysBetween(Date start, Date end)
  3. getDaysBetween(Date start, Date end)
  4. getDaysBetween(Date startDate, Date endDate)
  5. getDaysBetween(Date startDate, Date endDate)
  6. getDaysDiff(Date startDate, Date endDate)
  7. getDaysDifference(final Date begin, final Date end)
  8. getDiffBetweenQuarter(Date latestDate, Date current)
  9. getDiffDays(Date date1, Date date2)