我想以这种格式在我的应用上显示date
和time
Date: 14 - 19 Sep
Time: 16:30 to 18:30
我从服务器获取以下格式的数据,
"EventDate":"2015-09-14T16:30:00Z",
"EndDate":"2015-09-14T18:30:00Z",
我尝试过angualrjs date
过滤器,
现在我以下面的格式获取日期,
Sep 14, 2015 - Sep 19, 2015
我尝试过很多来自 SO 的例子,但对我不起作用,
Date formatting AngularJS to display only the day and month
如何以下列格式显示日期
Event Date: 14 - 19 Sep
Event Time: 16:30 to 18:30
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
$scope.Evdate = {
"j": [{
"EventDate": "2015-09-14T16:30:00Z",
"EndDate": "2015-09-14T18:30:00Z"
}]
}
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<div ng-app="myApp" ng-controller="myCtrl">
{{Evdate.j[0].EventDate | date}} - {{Evdate.j[0].EndDate | date}}
</div>
答案 0 :(得分:2)
你错过了格式参数。查看文档filter / date
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
$scope.Evdate = {
"j": [{
"EventDate": "2015-09-14T16:30:00Z",
"EndDate": "2015-09-14T18:30:00Z"
}]
}
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<div ng-app="myApp" ng-controller="myCtrl">
Event Date : {{Evdate.j[0].EventDate | date : 'd'}} - {{Evdate.j[0].EndDate | date : 'd MMM' }}<br />
Event time : {{Evdate.j[0].EventDate | date : 'HH:mm' : 'UTC' }} to {{Evdate.j[0].EndDate | date : 'HH:mm' : 'UTC' }}
</div>
&#13;
答案 1 :(得分:1)
一个月。试试这个。
{{Evdate.j[0].EventDate | date : 'd'}} - {{Evdate.j[0].EndDate | date : 'd MMM'}}
时间
{{Evdate.j[0].EventDate | date : 'HH:mm'}} - {{Evdate.j[0].EndDate | date : 'HH:mm'}}
希望它有所帮助。如果它不起作用,请通知我。