給定一個開始日期和一個結束日期,開始日期如果是周六或周天,那麼這就不算一周。結束日期哪怕是周一也要算是一周。最好能有代碼,謝謝!
有點小失誤,修改過的
public static int get(Date dtS, Date dtE) {
Calendar calS = Calendar.getInstance();
calS.setTime(dtS);
boolean isMonday = true;
Calendar calE = Calendar.getInstance();
calE.setTime(dtE);
if(calS.get(Calendar.DAY_OF_WEEK)!=Calendar.MONDAY){//不是周一不計入
calS.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
return (int) (Math.ceil((calE.getTimeInMillis()-calS.getTimeInMillis())/(86400000.0*7))-1);
}else{
return (int) (Math.ceil((calE.getTimeInMillis()-calS.getTimeInMillis())/(86400000.0*7)));
}
}