angularjs 日期格式在格式 yyyy/MM/dd 的控制器中不起作用
angularjs date Format doesn't work in controller for format yyyy/MM/dd
angularjs 中的日期格式在我格式化时不起作用:yyyy/MM/dd
来自日期选择器的日期 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
请帮助我。谢谢:)
你的过滤器工作正常。确保在执行过滤器之前将值分配给 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>
angularjs 中的日期格式在我格式化时不起作用:yyyy/MM/dd
来自日期选择器的日期 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
请帮助我。谢谢:)
你的过滤器工作正常。确保在执行过滤器之前将值分配给 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>