angularjs在简单网格表中过滤周

时间:2016-03-12 17:02:34

标签: javascript angularjs

我试图获取上周的数字...并使用angularjs中的上周数据过滤我的网格表...
所以在控制器

    Date.prototype.getWeek = function() {
      var onejan = new Date(this.getFullYear(), 0, 1);
      return Math.ceil((((this - onejan) / 86400000) + onejan.getDay() + 1) / 7);
    }

    var weekNumber = (new Date()).getWeek() - 3; //for last week

    $scope.pastWeek = weekNumber;

    console.log($scope.pastWeek); //today is sunday 12 mar 2016..so output-9
    console.log(weekNumber);

    var pastWeek = $filter('date')( $scope.pastWeek , 'w');
    console.log(pastWeek); //but here output is 01... why..!!

这里在pastWeek我期待09作为输出...我必须在某处wrog ...帮助提前谢谢

1 个答案:

答案 0 :(得分:0)

Date.prototype.getWeek = function() {
        var onejan = new Date(this.getFullYear(), 0, 1);
        return Math.ceil((((this - onejan) / 86400000) + onejan.getDay() + 1) / 7);
    }

    var weekNumber = (new Date()).getWeek();

通过这种方式,您可以获得上周的号码。