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; }