javascript - getting the count of date -
i want count of week day within month using angularjs. example getting count of saturdays in month. how can it? thank here code:
<!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>
in following way:
get/init:
- get date argument
- get year , month of input (yearvar, monthvar)
- get last day of month (last_day_of_month)
then
starting first day
var currdate = new date(yearvar, monthvar, 1)
find first occurrence of needed day
if(currdate.getday() == 6)
(6 sunday)remember value, multiple if until day less last_day_of_month
date api
https://developer.mozilla.org/en-us/docs/web/javascript/reference/global_objects/date
Comments
Post a Comment