如何使用javascript或jquery计算给定日期范围内的星期一?日期范围如下:
(2016-02-22 to 2016-02-29)
我经常搜索,但最后我什么都没得到。提前致谢
答案 0 :(得分:3)
试试这个fiddle
function getCountOf( date1, date2, dayToSearch )
{
var dateObj1 = parseDate(date1);
var dateObj2 = parseDate(date2);
var count = 0;
var week = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
var dayIndex = week.indexOf( dayToSearch );
while ( dateObj1.getTime() <= dateObj2.getTime() )
{
if (dateObj1.getDay() == dayIndex )
{
count++
}
dateObj1.setDate(dateObj1.getDate() + 1);
}
return count;
}