I'm struggling with simple implementation. I need to receive the amount of days, taking Saturdays and Sundays, from a certain range of dates. I tried to use Calendar because I can set the day (date), month and year and use calendar.get(Calendar.DAY_OF_WEEK)
to return the day of the week in full.
for (int i = firstYear; i <= currentYear; i++) {
for (int j = firstMonth; j <= currentMonth; j++) {
for (int d = firstDay; d <= currentDay; d++) {
calendar.clear();
calendar.set(i, j-1, d); // LEMRAR QUE O MÊS COMEÇA COM 0 E NÃO COM 1
if((calendar.get(Calendar.DAY_OF_WEEK) != Calendar.SUNDAY && calendar.get(Calendar.DAY_OF_WEEK) != Calendar.SATURDAY)){
count++;
}
}
}
}
The closest I got was the above code, but when, for example, the initial month is shorter but the day is not, it does not do what it should.