Java Day Between getDateDiff(final Date startDate, final Date endDate)

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

Description

get Date Diff

License

Apache License

Declaration

public static long getDateDiff(final Date startDate, final Date endDate) 

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 getDateDiff(final Date startDate, final Date endDate) {

        if (startDate != null && endDate != null) {
            final Calendar startCalendar = Calendar.getInstance();
            startCalendar.setTime(startDate);
            final long startDateMiliSeconds = startCalendar.getTimeInMillis();

            final Calendar endCalendar = Calendar.getInstance();
            endCalendar.setTime(endDate);
            final long endDateMiliSeconds = endCalendar.getTimeInMillis();
            final long result = (endDateMiliSeconds - startDateMiliSeconds) / 1000;
            if (result > 1) {
                return result;
            } else {
                return 0;
            }/*w  ww.ja  v  a2 s .c o m*/
        } else {
            return 0;
        }
    }
}

Related

  1. getBeteenDays(String begin, String end, String format)
  2. getBetweenDays(long longValue1, long longValue2)
  3. getBetweenDays(String start, String end)
  4. getBetweenTwoDayCalender(String startDay, String endDay)
  5. getDateDiff(Date date, int day)
  6. getDateDifference(Date date1, Date date2)
  7. getDateDifferenceinDays(Date date1, Date date2)
  8. getDateDiffYear(Date date, int diff, String... format)
  9. getDateWithDiff(Date date, int amount)