您好,我需要在某个日期范围内定义现有日期。我不会从开始到结束日期进行循环并像这里一样使用http://www.w3schools.com/jsref/jsref_getday.asp 是否可以通过某种方式计算它?
问问题
675 次
2 回答
3
function getDays(earlierDate, laterDate) {
var dayNames = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];
var elapsedDays = (laterDate - earlierDate) / 1000 / 60 / 60 / 24;
if (elapsedDays < 7) {
var dayArray = [];
for (i = 0; i <= elapsedDays; i++) {
dayArray.push(dayNames[(earlierDate.getDay()+i) % 7]);
}
return dayArray;
}
return dayNames;
}
并在 js 控制台中进行测试:
> getDays(new Date("03-01-2012"), new Date("03-01-2012"));
["Thursday"]
> getDays(new Date("03-01-2012"), new Date("03-05-2012"));
["Thursday", "Friday", "Saturday", "Sunday", "Monday"]
> getDays(new Date("03-01-2012"), new Date("03-05-2013"));
["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
于 2013-01-24T08:52:10.490 回答
0
var sevenDaysInMS = 604800000;
if (new Date(dTo - dFrom).getTime() >= sevenDaysInMS) {
$('.day_hid').attr(attrUnaviableDay, "true");
} else {
var dt = dFrom;
do {
var day = dt.getDay();
ActivateDaySelector(day);
dt.setDate(dt.getDate() + 1);
} while (dt <= dTo);
}
我认为没关系。你怎么看 ?
于 2013-01-24T08:49:30.010 回答