//查找两个时间段内的所有日期(除去周六、周天)
public static List<Date> getDutyDays(Date startDate, Date endDate) {
List<Date> list = new ArrayList<>();
Calendar tempStart = Calendar.getInstance();
tempStart.setTime(startDate);
Calendar tempEnd = Calendar.getInstance();
tempEnd.setTime(endDate);
tempEnd.add(Calendar.DATE, +1);// 包含结束日期+1,将结束日期放入结果集
while (tempStart.before(tempEnd)||tempStart.equals(tempEnd)) {
//int day = tempStart.getTime().getDay();
int day = tempStart.get(Calendar.DAY_OF_WEEK) - 1;
if(day != 6 && day != 0){
list.add(tempStart.getTime());
System.out.println(tempStart.getTime());
}
tempStart.add(Calendar.DAY_OF_YEAR, 1);
}
return list;
}
public static void main(String[] args) {
List<Date> dutyDays = getDutyDays(new Date(), stringToDate2("2021-06-30"));
}
08-07
717
12-04
662