我試圖讓兩個日期之間的工作日。 示例:stdate = 28/10/2011和endate = 04/11/2011。這應該是6個工作日,但它只給5天。使用Javascript獲得工作日
var workingdays = 0;
var weekday = new Array(7);
weekday[0]="Sunday";
weekday[1]="Monday";
weekday[2]="Tuesday";
weekday[3]="Wednesday";
weekday[4]="Thursday";
weekday[5]="Friday";
weekday[6]="Saturday";
while (stdate <= endate)
{
var day = weekday[stdate.getDay()];
if(day != "Saturday" && day != "Sunday")
{
workingdays++;
}
console.log(weekday[stdate.getDay()]);
stdate = new Date(stdate.getTime() + 86400000);
}
控制檯日誌顯示下面的結果。
Friday
Saturday
Sunday
Sunday
Monday
Tuesday
Wednesday
Thursday
星期天由於某種原因顯示兩次。任何幫助,將不勝感激。
你如何通過你的時間(開始和結束)的javascript?你會轉換一個字符串嗎? – emt14