1 $scope.getDate = new Date();2 3 //可以当前日期4 $scope.nowDate = $filter("date")($scope.getDate, "yyyy-MM-dd");5 //获取前一天日期6 $scope.oldDate = $filter("date")($scope.getDate - 86400000, "yyyy-MM-dd");7 console.log($scope.nowDate,$scope.oldDate);
注意:记得依赖注入$filter
输出:2017-10-20 2017-10-19