2017-05-16 166 views
0

我使用從https://github.com/500tech/angular-simple-calendar獲取的日曆。星期一從星期一開始JavaScript

在此日曆星期從週日開始,在這個函數的計算方法:

calculateWeeks = function() { 
    $scope.weeks = []; 
    var week = null; 
    var daysInCurrentMonth = new Date($scope.selectedYear, MONTHS.indexOf($scope.selectedMonth) + 1, 0).getDate(); 
    for (var day = 1; day < daysInCurrentMonth + 1; day += 1) { 
     var dayNumber = new Date($scope.selectedYear, MONTHS.indexOf($scope.selectedMonth), day).getDay(); 
     week = week || [null, null, null, null, null, null, null]; 
     week[dayNumber] = { 
     year: $scope.selectedYear, 
     month: MONTHS.indexOf($scope.selectedMonth), 
     day: day 
     }; 

     if (allowedDate(week[dayNumber])) { 
     if ($scope.events) { bindEvent(week[dayNumber]); } 
     } else { 
     week[dayNumber].disabled = true; 
     } 

     if (dayNumber === 6 || day === daysInCurrentMonth) { 
     $scope.weeks.push(week); 
     week = undefined; 
     } 
    } 
    }; 

我應該做什麼樣的變化,從星期一開始一週?

+0

'dayNumber =(dayNumber || 7) - 1;'應該這樣做時,'VAR dayNumber'線之後。 –

+0

這工作謝謝! – AlexP

回答

1

你可以通過添加6模7改變dayNumber定義:

var dayNumber = (new Date($scope.selectedYear, MONTHS.indexOf($scope.selectedMonth), day) 
       .getDay() + 6) % 7; 
相關問題