Java Date to Day getDayBetween(Date startDate, Date endDate)

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

Description

get Day Between

License

Apache License

Declaration

public static final Integer getDayBetween(Date startDate, 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 final Integer getDayBetween(Date startDate, Date endDate) {
        Calendar start = Calendar.getInstance();
        start.setTime(startDate);/*from w w w .ja  v  a 2 s .  c o  m*/
        start.set(Calendar.HOUR_OF_DAY, 0);
        start.set(Calendar.MINUTE, 0);
        start.set(Calendar.SECOND, 0);
        start.set(Calendar.MILLISECOND, 0);
        Calendar end = Calendar.getInstance();
        end.setTime(endDate);
        end.set(Calendar.HOUR_OF_DAY, 0);
        end.set(Calendar.MINUTE, 0);
        end.set(Calendar.SECOND, 0);
        end.set(Calendar.MILLISECOND, 0);

        long n = end.getTimeInMillis() - start.getTimeInMillis();
        return (int) (n / (60 * 60 * 24 * 1000l));
    }
}

Related

  1. getDay(Date date)
  2. getDay(Date date, int day)
  3. getDay(Date dateParam)
  4. getDay(java.util.Date date)
  5. getDay(String strDate)
  6. getDayCount(java.util.Date _startDate, java.util.Date _endDate)
  7. getDayEnd(Date date)
  8. getDayEnd(Date date)
  9. getDayEnd(Date date)