1
我用Javascript编写的函数有问题。我试图在开始和结束之间获得一组日期。获取开始日期和结束日期之间的一个数组
功能:
function getDateArray(startDate, endDate) {
var dateArray = new Array(),
currentDate = new Date(startDate),
lastDay = new Date(endDate);
while (currentDate <= lastDay) {
if (!(currentDate.getUTCDay() === 0 || currentDate.getUTCDay() === 6)) {
//currentDate.toUTCString(); //This line is redundant
dateArray.push(currentDate);
}
currentDate.setDate(currentDate.getDate() + 1);
}
return dateArray;
}
每当我打电话有两个日期这样的功能:
开始日期= 2015年10月6日 和结束日期= 2015年10月12日
我得到了不想要的结果:
Tue Oct 13 2015 00:00:00 GMT+0200 (South Africa Standard Time)
Tue Oct 13 2015 00:00:00 GMT+0200 (South Africa Standard Time)
Tue Oct 13 2015 00:00:00 GMT+0200 (South Africa Standard Time)
Tue Oct 13 2015 00:00:00 GMT+0200 (South Africa Standard Time)
Tue Oct 13 2015 00:00:00 GMT+0200 (South Africa Standard Time)
Tue Oct 13 2015 00:00:00 GMT+0200 (South Africa Standard Time)
Tue Oct 13 2015 00:00:00 GMT+0200 (South Africa Standard Time)
请如果有人可以highligh对我来说这里有什么不对?到那个
dateArray.push(currentDate);
:
'currentDate.toUTCString();'是一个无操作;你必须在某处分配结果。如果目标是推送字符串表单,则需要推送该值的返回值。 – ShadowRanger