Java Date Between daysBetween2Dates(Date d1, Date d2)

Here you can find the source of daysBetween2Dates(Date d1, Date d2)

Description

Find out the distance between two dates

License

Open Source License

Parameter

Parameter Description
d1 From date
d2 To Date

Return

no of days difference between two days.

Declaration

public static long daysBetween2Dates(Date d1, Date d2) 

Method Source Code

//package com.java2s;

import java.util.Calendar;

import java.util.Date;

public class Main {
    /**//www .  j a  v a2 s  . c  o  m
     * Find out the distance between two dates
     * @param d1 From date
     * @param d2 To Date
     * @return no of days difference between two days.
     */
    public static long daysBetween2Dates(Date d1, Date d2) {
        Calendar c1 = Calendar.getInstance(); //new GregorianCalendar();
        Calendar c2 = Calendar.getInstance(); //new GregorianCalendar();
        c1.setTime(d1);
        c2.setTime(d2);
        return (c2.getTime().getTime() - c1.getTime().getTime()) / (24 * 3600 * 1000);
    }
}

Related

  1. daysBetween(String from, String to)
  2. daysBetween(String from, String to, String form)
  3. daysBetween(String from, String to, String format)
  4. daysBetween(String from, String to, String format)
  5. daysBetween(String smdate, String bdate)
  6. daysBetween2Dates(Date startDate, Date endDate)
  7. daysBetweenCalendars(Calendar date1, Calendar date2)
  8. daysBetweenDate(Integer startDate, Integer endDate)
  9. daysBetweenDates(Date beginDate, Date endDate)