public static int getDaysBetween (String beginDate, String endDate) throws ParseException
{
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
Date bDate = format.parse(beginDate);
Date eDate = format.parse(endDate);
Calendar d1 = new GregorianCalendar();
d1.setTime(bDate);
Calendar d2 = new GregorianCalendar();
d2.setTime(eDate);
int days = d2.get(Calendar.DAY_OF_YEAR) - d1.get(Calendar.DAY_OF_YEAR);
int y2 = d2.get(Calendar.YEAR);
if (d1.get(Calendar.YEAR) != y2)
{
d1 = (Calendar) d1.clone();
do {
days += d1.getActualMaximum(Calendar.DAY_OF_YEAR);//得到当年的实际天数
d1.add(Calendar.YEAR, 1);
} while (d1.get(Calendar.YEAR) != y2);
}
return days;
}
转载于:https://blog.51cto.com/dashu1021/839279