逐步增加小时,然后增加24小时。并在每个步骤之后检查是否在星期六或星期天结束。在每种情况下,都需要增加24小时。那应该做你想要的。
public Date getTaskEndTime(Calendar startDate, int hours){ while (hours > 0){ int step = 0; if(hours > 24) step = 24; else step = hours; hours -= step; startDate.add(Calendar.HOUR_OF_DAY, step); int dayOfWeek = startDate.get(Calendar.DAY_OF_WEEK); if(dayOfWeek == Calendar.SATURDAY) hours += 24; if(dayOfWeek == Calendar.SUNDAY) hours += 24; } return startDate.getTime();}


