Java Day From daysAfter(Date earlierDate, Date laterDate)

Here you can find the source of daysAfter(Date earlierDate, Date laterDate)

Description

days After

License

Open Source License

Declaration

public static int daysAfter(Date earlierDate, Date laterDate) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.*;

public class Main {
    private static final Calendar CALENDAR = Calendar.getInstance();
    private static final Calendar CALENDAR2 = Calendar.getInstance();

    public static int daysAfter(Date earlierDate, Date laterDate) {
        final Calendar earlier = CALENDAR;
        final Calendar later = CALENDAR2;

        if (laterDate.before(earlierDate))
            return 0;

        earlier.setTime(earlierDate);//from   w w  w  . ja  v a  2 s .com
        later.setTime(laterDate);

        int daysLater = later.get(Calendar.DAY_OF_YEAR) - earlier.get(Calendar.DAY_OF_YEAR);
        for (int year = earlier.get(Calendar.YEAR); year < later.get(Calendar.YEAR); year++) {
            earlier.set(Calendar.YEAR, year);
            daysLater += earlier.getActualMaximum(Calendar.DAY_OF_YEAR);
        }

        return daysLater;
    }
}

Related

  1. dayNumberToTimestamp(short dateNumber)
  2. days(int d)
  3. days(int month, int year)
  4. days(int num)
  5. days(int year, int month)
  6. daysAndHours(int hours)
  7. daysBetweenTime(long start, long end)
  8. daysInFebruary(int year)
  9. daysInMonthForYear(int commonMonthIndex, int yearInteger)