开发者

I want to calculate Saturday's and Sunday's in a date range

开发者 https://www.devze.com 2023-01-13 15:47 出处:网络
I want开发者_如何学C to calculate Saturday\'s and Sunday\'s in a date range? How can i ?iterate in days and so :

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消