2017-08-03 74 views
1
在angularjs

日期格式不工作的时候格式:angularjs日期格式不控制器工作为格式YYYY/MM/DD

:从日期选择器 ng-model="Periode1" = 01 January 2016

我试图yyyy/MM/dd

日期

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

你过滤器工作正常。确保在执行过滤器之前将值赋给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>

+0

好,谢谢,我试图让一个功能。并成功:) – septian