我想在两个约会之间得到工作日.
示例:stdate = 28/10/2011 and endate = 04/11/2011.这应该是6个工作日,但它只给5天.
示例:stdate = 28/10/2011 and endate = 04/11/2011.这应该是6个工作日,但它只给5天.
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
由于某种原因,周日出现两次.任何帮助,将不胜感激.