How to subtract date in angularjs
I am trying to make a list from the current date to the last 31 days. I am trying to use ng-repeat
to make a list today until day 31. I can make a list, but not a date. I am trying code like this
Html
<ion-list>
<ion-item class="animate-repeat" ng-repeat="i in rep">
{{trip}}
{{besok}}
</ion-item>
</ion-list>
Js
$scope.rep = [];
for (var i=0; i < 31; i++) {
$scope.trip = new Date();
$scope.besok = $scope.trip.setDate($scope.trip.getDate()- i);
$scope.rep.push(i);
}
and it will look like this. He cannot subtract a day. How do I reduce it properly in angularjs? help me solve this problem. Thanks to
+3
source to share
1 answer
Try it. I know this is not angular code. the same logic will work as in
var rep = [];
for (var i=0; i < 31; i++) {
var trip = new Date();
var besok =new Date(trip.getTime() - i*(24*60*60*1000));
rep.push(besok);
}
console.log(rep);
+3
source to share