如何将日期转换为2016年4月8日格式?
// in your controller:
$scope.date = '20140313T00:00:00';
// in your view, date property, filtered with date filter and format 'MM dd yyyy'
<div ng-bind="date | date:'MM dd yyyy'"></div>
答案 0 :(得分:1)
$scope..DayofDate = "";
$scope.Monthofdate = "";
$scope.DaySuffix = "";
$scope.getDateFormat = function (date) {
var suffixes = ["th", "st", "nd", "rd"];
var dtfilter = $filter('date')(date, 'dd');
$scope.DayofDate = dtfilter;
var mtfilter = $filter('date')(date, 'MMM yyyy');
$scope.Monthofdate = mtfilter;
var day = parseInt(dtfilter.slice(-2));
var relevantDigits = (day < 30) ? day % 20 : day % 30;
var suffix = (relevantDigits <= 3) ? suffixes[relevantDigits] : suffixes[0];
$scope.DaySuffix = suffix;
}
并在您的html页面中
<div ng-init="getDateFormat(date)">
<p>Date : {{DayofDate}} <sup>{{DaySuffix}}</sup>{{Monthofdate}}</p>
</div>
答案 1 :(得分:0)
试试这个:
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.8/angular.min.js"></script>
</head>
<body ng-app="myApp" ng-controller="myCtrl">
{{myDate | date: 'dd MMM yyyy'}}
<script>
//Module Declaration
var app = angular.module('myApp',[]);
//Controller Declaration
app.controller('myCtrl',function($scope){
$scope.myDate="20140313T00:00:00";
});
</script>
</body>
</html>
有关详细信息,请参阅此文档:https://docs.angularjs.org/api/ng/filter/date