Here you can find the source of daysDiff(final Date data1, final Date data2)
Parameter | Description |
---|---|
data1 | The first date |
data2 | The second date |
public static int daysDiff(final Date data1, final Date data2)
//package com.java2s; //License from project: Open Source License import java.util.Calendar; import java.util.Date; public class Main { /**//from ww w . ja v a2s . c o m * Get the difference in days of two given dates. * * @param data1 * The first date * @param data2 * The second date * @return The difference in days of two given dates */ public static int daysDiff(final Date data1, final Date data2) { long ini = getCalendarInstance(data1).getTimeInMillis(); long fim = getCalendarInstance(data2).getTimeInMillis(); long nroHoras = (fim - ini) / 1000 / 3600; int nroDias = (int) nroHoras / 24; return nroDias; } /** * Get the calendar instance of a given date * @param date * The date * @return The calendar instance */ public static Calendar getCalendarInstance(final Date date) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date); return calendar; } }