yyyy/MM/dd
datepicker ng-model="Periode1"
= 01 January 2016
我试过了:
var p1 = new Date($scope.Periode1);
$scope.period1Convert = $filter('date')(p1, "yyyy/MM/dd");
output : null
还有:
var d = new Date($scope.Periode1);
var curr_date = d.getDate();
var curr_month = d.getMonth();
curr_month++;
var curr_year = d.getFullYear();
$scope.period1Convert = (curr_year + "/" + curr_month + "/" + curr_date);
output : NaN/NaN/NaN
请帮帮我。谢谢:))
答案 0 :(得分:0)
你过滤器工作正常。确保在执行过滤器之前将值赋给ng-model
变量。
angular.module("app",[])
.controller("ctrl",function($scope, $filter){
$scope.Periode1 = "01 January 2016";
var p1 = new Date($scope.Periode1);
$scope.period1Convert = $filter('date')(p1, "yyyy/MM/dd");
console.log($scope.period1Convert)
})
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app" ng-controller="ctrl">
</div>