Java Day Between getNumDaysDiffExclTime(Date date1, Date date2)

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

Description

This method returns number of days between date1 and date2, including date1 and date2 regardless of the date time.

License

Open Source License

Parameter

Parameter Description
date1 a parameter
date2 a parameter

Declaration

public static int getNumDaysDiffExclTime(Date date1, Date date2) 

Method Source Code

//package com.java2s;
/**/*w ww. j a va2s .c  o  m*/
 * Copyright (C) 2013 Company. All Rights Reserved. 
 * 
 * This software is the proprietary information of Company . 
 * Use is subjected to license terms. 
 *
 * @since Jul 17, 2013 11:48:25 PM
 * @author SPA
    
 *
 */

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

public class Main {
    /**
     * This method returns number of days between date1 and date2, including
     * date1 and date2 regardless of the date time. Eg 1 Jan 06 2000hrs to 3 Jan
     * 06 1900hrs will return as 3 days. This method is used for
     * 
     * @param date1
     * @param date2
     * @return
     */
    public static int getNumDaysDiffExclTime(Date date1, Date date2) {
        int result = 0;
        Calendar cal = new GregorianCalendar();
        cal.setTime(date1);
        while (!cal.getTime().after(date2)) {
            cal.add(Calendar.DAY_OF_MONTH, 1);
            result++;
        }
        return result;
    }
}

Related

  1. getManyWeeksDifference(Date a, Date b)
  2. getMinuteDiffByTime(Date time1, Date time2)
  3. getMinutesDifference(final Date begin, final Date end)
  4. getMonthDifference(Date from, Date to)
  5. getMonthsDifference(Date earlierDate, Date laterDate)
  6. getTimeDifference(Date d1, Date d2)
  7. getTimeDifference(Date date1, Date date2)
  8. getTimeDifference(Date otherDate)
  9. getTodayDiff(String diffDate)