2017-02-10 4 views
0

たとえば、1日または1か月-1の日付を取得したいのですが、それをどのように管理できますか?正確な日付を取得するAngularJS

resolve: { 
    data: function($route, $http, $filter) { 
    var today = new Date(); 
    var formattedDate = $filter('date')(today, 'yyyyMMdd'); 
    return $http.get('./app/sources/stats/'+$route.current.params.mag+'/'+$route.current.params.mag+'_20170205.json').then(function(response) { 
     return response.data; 
    }); 
    } 
} 
+0

のために行く* "私はその日の日付を取得したい - 1か月-1" * - あなたはこれを解読することができますか? – dfsq

+0

getDate()とgetMonth()関数を使用して、不明な点を確認してください。 –

+0

https://docs.angularjs.org/api/ng/filter/date お試しください。 –

答えて

1
var today = new Date(); 
var yesterday = new Date(today); 
yesterday.setDate(today.getDate() - 1); 

同じsetMonthgetMonth

+0

私はyyyyMMddを取得するためにフィルタを使用しました - > var previousDay = new Date(today); var formattedDate2 = $ filter( 'date')(previousDay.setDate(today.getDate() - 1)、 'yyyyMMdd'); ありがとうございます! – Matieu

0

これは私が私のプロジェクトでの日を追加するためにやったことです:

今の私がいることを持っています。多分これがあなたを助けるでしょう!

var app = angular.module('my-app', []); 
    app.controller("my-controller", function($scope) { 
    $scope.name = "world"; 
    $scope.mydate = new Date("2016-08-16T15:10:10.530Z"); 
    var numberOfDaysToAdd = 5; 
    $scope.newdate = $scope.mydate.setDate($scope.mydate.getDate() + numberOfDaysToAdd); 
    }); 
関連する問題