I want开发者_如何学C to calculate Saturday's and Sunday's in a date range? How can i ?
iterate in days and so :
Calendar date ;//initiate with your date
int day = date.get(Calendar.DAY_OF_WEEK); // 1=Sunday , 2=Monday , ...
check the day:
if(day == 1 || day == 7)
{
//add to your list this **date** (for example List<Calender>
}
and so on.
Find 1st Saturday&Sunday in the range, then Calendar.add(Calendar.DATE, 7) to get Saturdays&Sundays until end of range. It's faster than checking each day in the range.
精彩评论