Java Day Between dayDiff(Date start, Date end)

Here you can find the source of dayDiff(Date start, Date end)

Description

day Diff

License

Apache License

Declaration

public static long dayDiff(Date start, 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 long dayDiff(Date start, Date end) {
        long day = compareDate(start, end);
        if (day == 0) {
            return 0;
        }/*  w  w w . j  av  a 2 s .  com*/
        if (day > 0) {
            return (day - 1) / 1000 / 60 / 60 / 24 + 1;
        } else {
            return (day + 1) / 1000 / 60 / 60 / 24 - 1;
        }

    }

    public static long compareDate(Date start, Date end) {
        long temp = 0;
        Calendar starts = Calendar.getInstance();
        Calendar ends = Calendar.getInstance();
        starts.setTime(start);
        ends.setTime(end);
        temp = ends.getTime().getTime() - starts.getTime().getTime();
        return temp;
    }
}

Related

  1. calculateDifference(Date d1, Date d2)
  2. calculateDifferMonths(Date date1, Date date2, boolean isTruncate)
  3. calculateNumberOfDays(String dateStr)
  4. countDiffDay(String beginDateBase, String endDateBase)
  5. dayDiff(Date d1, Date d2)
  6. daysDiff(final Date data1, final Date data2)
  7. differentDaysByMillisecond(Date date1, Date date2)
  8. diffInDays(Date date1, Date date2)
  9. getBeteenDays(String begin, String end, String format)