Java Date Between daysBetween(final Date date1, final Date date2)

Here you can find the source of daysBetween(final Date date1, final Date date2)

Description

days Between

License

Open Source License

Declaration

public static int daysBetween(final Date date1, final Date date2) 

Method Source Code

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

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

public class Main {
    public static int daysBetween(final Date date1, final Date date2) {
        return (int) ((getZeroTimeDate(date1).getTime() - getZeroTimeDate(date2).getTime())
                / (1000 * 60 * 60 * 24));
    }//w  w  w  . ja v a  2s.co  m

    public static Date getZeroTimeDate(final Date date) {
        final Calendar calendar = Calendar.getInstance();

        calendar.setTime(date);
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);

        return calendar.getTime();
    }
}

Related

  1. daysBetween(Date smdate, Date bdate)
  2. daysBetween(Date smdate, Date bdate)
  3. daysBetween(Date smdate, Date bdate)
  4. daysBetween(Date smdate, Date bdate)
  5. daysBetween(Date startDate, Date endDate)
  6. daysBetween(final Date dateA, final Date dateB)
  7. daysBetween(String bdate, String edate)
  8. daysBetween(String beginDate, String endDate)
  9. daysBetween(String from, String to)