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