我想用javascript计算一个月内的星期日数 [英] i want calculate number of sundays in a month by using javascript
本文介绍了我想用javascript计算一个月内的星期日数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想通过使用javascript
i want calculate number of sundays in a month by using javascript
推荐答案
function sundays(year, month) {
var day = 1;
var counter = 0;
var date = new Date(year, month, day);
while(date.getMonth() === month) {
if(date.getDay() === 6) {
counter++;
}
day++;
date = new Date(year, month, day);
}
return counter;
}
sundays(2012, 5);
https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Date [ ^ ]
来源: http://stackoverflow.com/questions/13106961/get-number-of -sundays-in-a-month-using-javascript [ ^ ]
https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Date[^]
Source : http://stackoverflow.com/questions/13106961/get-number-of-sundays-in-a-month-using-javascript[^]
这篇关于我想用javascript计算一个月内的星期日数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文