var range = getDates(new Date(), new Date().addDays(7));
我希望“范围”是一个日期对象数组,两个日期之间的每一天都有一个。
诀窍是它也应该处理月份和年份的界限。
function (startDate, endDate, addFn, interval) { addFn = addFn || Date.prototype.addDays; interval = interval || 1; var retVal = []; var current = new Date(startDate); while (current <= endDate) { retVal.push(new Date(current)); current = addFn.call(current, interval); } return retVal; }