Java Calendar Between daysBetweenxX(Calendar start, Calendar end)

Here you can find the source of daysBetweenxX(Calendar start, Calendar end)

Description

days Betweenx X

License

Open Source License

Declaration

public static long daysBetweenxX(Calendar start, Calendar end) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) Emil Crumhorn - Hexapixel.com - emil.crumhorn@gmail.com
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors://from   ww w  .  ja  v  a 2 s. com
 *    emil.crumhorn@gmail.com - initial API and implementation
 *******************************************************************************/

import java.util.Calendar;

import java.util.GregorianCalendar;

public class Main {
    private static final long MILLISECONDS_IN_DAY = 24 * 60 * 60 * 1000;

    public static long daysBetweenxX(Calendar start, Calendar end) {
        //reset all hours mins and secs to zero on start date
        Calendar startCal = GregorianCalendar.getInstance();
        startCal.setTime(start.getTime());
        startCal.set(Calendar.HOUR_OF_DAY, 0);
        startCal.set(Calendar.MINUTE, 0);
        startCal.set(Calendar.SECOND, 0);
        long startTime = startCal.getTimeInMillis();

        //reset all hours mins and secs to zero on end date
        Calendar endCal = GregorianCalendar.getInstance();
        endCal.setTime(end.getTime());
        endCal.set(Calendar.HOUR_OF_DAY, 0);
        endCal.set(Calendar.MINUTE, 0);
        endCal.set(Calendar.SECOND, 0);
        long endTime = endCal.getTimeInMillis();

        return (endTime - startTime) / MILLISECONDS_IN_DAY;
    }
}

Related

  1. daysBetween(final Calendar cal1, final Calendar cal2)
  2. daysBetween(final Calendar startDate, final Calendar endDate)
  3. daysBetween(final Calendar startDate, final Calendar endDate)
  4. daysBetweenCalendarDates(final Calendar firstDate, final Calendar secondDate)
  5. daysBetweenForDate(Calendar startDate, Calendar endDate)
  6. getDaysBetween(Calendar d1, Calendar d2)
  7. getDaysBetween(Calendar d1, Calendar d2)
  8. getDaysBetween(Calendar firstDate, Calendar lastDate)
  9. getDaysBetween(Calendar start, Calendar end)