javascript - javascript - 使用Date对象查找一个月内的所有日期?

有没有办法用日期对象来查找天? 我找到了这个链接,例如: 显示月份的所有日期,但是,我不太理解它,而且它是Java写的,我正在试图在javascript中找到一个解决方案。




 * @param {int} The month number, 0 based

 * @param {int} The year, not zero based, required to account for leap years

 * @return {Date[]} List with date objects for each day of the month


function getDaysInMonth(month, year) {

 var date = new Date(year, month, 1);

 var days = [];

 while (date.getMonth() === month) {

 days.push(new Date(date));

 date.setDate(date.getDate() + 1);


 return days;



var numOfDays = new Date(2012, 10, 0).getDate(); //use 0 here and the actual month

var days = new Array();

//This will construct an array with all the elements represent the day of the week 

//(i.e. Oct 30th would be days[30-1] or days[29]) and the value would be the actual 

//day of the week (i.e. Tuesday which is representing by the number 2)

for(var i=0;i<=numOfDays;i++)


 days[i] = new Date(2012,9,i+1).getDay(); //use month-1 here 


//This will give you a number from 0 - 6 which represents (Sunday - Saturday)