使用javascript获取一个月中的星期天数 [英] get number of sundays in a month using javascript
本文介绍了使用javascript获取一个月中的星期天数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用javascript查找一个月中的星期天编号
我正在将月份和年份传递给函数
请建议
I want to find the no of Sundays in a month using javascript
i am passing month and year to a function
Please suggest
推荐答案
1.您没有分享您尝试过的内容
2.您在多个论坛上发布了此内容
这是询问者的期望:
一个. 先尝试您要做什么!您可能会发现它并不难.
b.拟定看起来像问题/无法解决的问题,由您完成.
目前,您在这里有一个答案:获取星期日的数量在一个月内使用javascript [ ^ ]
它说:
1. You did not share what you tried
2. You posted this at multiple forums
Here is what is expected of enquirers:
a. TRY first what you want to do! You may find that it''s not that hard.
b. Formulate what was done by you that looks like an issue/not working.
For now, here, you have an answer: get number of sundays in a month using javascript[^]
It says:
function sundaysInMonth( m, y ) {
var days = new Date( y,m,0 ).getDate();
var sundays = [ 8 - (new Date( m +'/01/'+ y ).getDay()) ];
for ( var i = sundays[0] + 7; i < days; i += 7 ) {
sundays.push( i );
}
return sundays;
}
alert( sundaysInMonth( 10,2012 ) ); //=> [ 7,14,21,28 ]
alert( sundaysInMonth( 10,2012 ).length ); //=> 4
此外,在这里,了解如何在JavaScript中处理日期操作: MSDN :计算日期和时间(JavaScript) [ ^ ]
Further, here, learn how to handle date manipulations in JavaScript: MSDN: Calculating Dates and Times (JavaScript)[^]
这篇关于使用javascript获取一个月中的星期天数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文