java 两个日期天数之差

两个日期之间的星期六,还有星期日 不算急.....................
2024-11-15 09:18:08
推荐回答(2个)
回答1:

Calendar cal1 = Calendar.getInstance();

Calendar cal2 = Calendar.getInstance();

String strMaxDate = "1995-12-06";

String strMinDate = "1995-12-01";

String compile = "yyyy-MM-dd";

SimpleDateFormat sdf = new SimpleDateFormat(compile);

try
{
cal1.setTime(new java.sql.Date(sdf.parse(strMaxDate).getTime()));

cal2.setTime(new java.sql.Date(sdf.parse(strMinDate).getTime()));

long lCal1 = cal1.getTimeInMillis();

long lCal2 = cal2.getTimeInMillis();

long l = lCal1 - lCal2;

System.out.println(l/1000/60/60/24);
}
catch (ParseException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}

回答2:

只能循环算吧?