Here you can find the source of getNumberOfDaysBetweenDates(Date beginDate, Date endDate)
public static Integer getNumberOfDaysBetweenDates(Date beginDate, Date endDate)
//package com.java2s; /**/* w ww .j a va2 s .co m*/ * Copyright ? 2002 Instituto Superior T?cnico * * This file is part of FenixEdu Core. * * FenixEdu Core is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * FenixEdu Core is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with FenixEdu Core. If not, see <http://www.gnu.org/licenses/>. */ import java.util.Calendar; import java.util.Date; public class Main { public static Integer getNumberOfDaysBetweenDates(Date beginDate, Date endDate) { Calendar c1 = Calendar.getInstance(); Calendar c2 = Calendar.getInstance(); c1.setTime(beginDate); c2.setTime(endDate); long timeBetweenInMillis = c2.getTimeInMillis() - c1.getTimeInMillis(); Integer numberDaysBetweenDates = new Integer(new Long(timeBetweenInMillis / (3600000 * 24)).intValue()); return numberDaysBetweenDates; } }