简体   繁体   English

日期过滤器格式化Angularjs

[英]Date filter formatting Angularjs

I want to show date and time on my app in this format, 我想以这种格式在我的应用上显示datetime

Date: 14 - 19 Sep
Time: 16:30 to 18:30

And I'm getting data from server in below format, 我从服务器获取以下格式的数据,

"EventDate":"2015-09-14T16:30:00Z",
"EndDate":"2015-09-14T18:30:00Z",

I tried angualrjs date filter, 我试过angualrjs date过滤器,

and now I'm getting date in below format, 现在我收到以下格式的日期,

Sep 14, 2015 - Sep 19, 2015

I tried many examples from SO but didn't work for me, 我从SO那里尝试过很多例子,但对我来说不起作用,

Date formatting AngularJS to display only the day and month 日期格式化AngularJS仅显示日期和月份

How can I display my Date in following format, 如何以下列格式显示日期,

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> 

You just missed the format argument. 你刚刚错过了格式参数。 Look the documentation 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" }] } }); 
 <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> 

For month. 一个月。 Try this. 尝试这个。

{{Evdate.j[0].EventDate | date : 'd'}} - {{Evdate.j[0].EndDate | date : 'd MMM'}}

For time 时间

{{Evdate.j[0].EventDate | date : 'HH:mm'}} - {{Evdate.j[0].EndDate | date : 'HH:mm'}}

Hope it helps. 希望能帮助到你。 Notify me if it doesn't work. 如果它不起作用,请通知我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM