开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜