我想使用angularJS来计算一个月内一周的天数。例如,获取一个月中星期六的计数。我怎么才能得到它呢?谢谢以下是我的代码:
<!doctype html>
<html ng-app="myApp">
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.9.0/moment.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular.min.js"></script>
</head>
<body>
<div ng-app="myApp" ng-controller="myCtrl" ng-init="getdates()">
<p ng-if="x='Sat'">{{dates.length}}</p>
<div ng-repeat="x in dates">
<input type="checkbox" ><p ng-show="x">{{x | format:'ddd'}}</p></input>
</div>
</div>
<script>
angular.module('myApp', [])
.controller('myCtrl', function($scope) {
$scope.dates=[];
$scope.getdates=function(){
for(i=0;i<31;i++){
$scope.myDate = i+' Feb 2015 00:00:00 GMT';
$scope.dates.push($scope.myDate)
}
};
})
.filter('format', function() {
return function(input, format) {
return moment(new Date(input)).format(format);
};
})
;
</script>
</body>
</html>发布于 2015-06-01 02:48:12
通过以下方式:
GET/INIT:
然后
var currDate = new Date(yearVar, monthVar, 1)查找所需日期的第一个匹配项(6为if(currDate.getDay() == 6) )
如果当天小于last_day_of_month,请记住此值,如果
,则为multiple
DATE API
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date
https://stackoverflow.com/questions/30560957
复制相似问题