public class DateTest {
public static void main(String[] args) throws ParseException {
int dutyDays = getDutyDays("2018-12-03","2019-01-22");
System.out.println(dutyDays);//37天
}
@SuppressWarnings("deprecation")
private static int getDutyDays(String startDateStr, String endDateStr) throws ParseException {
int result = 0;
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
Date startDate = df.parse(startDateStr);
Date endDate = df.parse(endDateStr);
while (startDate.compareTo(endDate) <= 0) {
if (startDate.getDay() != 6 && startDate.getDay() != 0)
result++;
startDate.setDate(startDate.getDate() + 1);
}
return result;
}
}