AngularJS:如何格式化 ISO8601 日期格式? [英] AngularJS: How to format ISO8601 date format?
问题描述
我正在使用 bootstrap-datetimepicker 并使用 ISO8601 日期时间格式作为 yyyy-mm-ddThh:ii:ssZ
在他们的选项部分提到
I am using bootstrap-datetimepicker and using ISO8601 datetime format as yyyy-mm-ddThh:ii:ssZ
as mentioned in their options section
在我的控制器中,我这样做
In my controller, I do
transaction.date = $('.form_datetime input').val();
将数据作为 (console.log) 发送到后端
which sends the data to backend as (console.log)
created_on: "Wed, 08 May 2013 23:18:32 -0000"
并在数据库中保存为
2013-05-08 16:18:32-07
在我的模板中,我这样做
In my template, I do
<td>{{ transaction.created_on | date:'medium'}}</td>
我在我的 HTML 上看到输出为
and I see the output on my HTML as
Wed, 08 May 2013 23:18:32 -0000
但根据 Angular doc,它应该用于格式 2010 年 10 月 28 日晚上 8:40:23
But as per the Angular doc, it should be for format Oct 28, 2010 8:40:23 PM
我缺少什么?
推荐答案
现在,我已经创建了一个过滤器
For now, I have created a filter
angular.module('customFilters', []).
filter('dateInMillis', function() {
return function(dateString) {
return Date.parse(dateString);
};
});
在 app.js
中作为依赖添加为
added as dependency in app.js
as
var app = angular.module('myApp', [
'$strap.directives', 'ngCookies', 'categoryServices', 'transactionServices',
'customFilters'
]);
并在 HTML
中将其用作
<!-- added dateInMillis to pass to date to filter Angular way -->
<td>{{ transaction.created_on | dateInMillis | date: 'medium'}}</td>
并且将 HTML
上的日期显示为
and that presents date on HTML
as
May 8, 2013 5:14:36 PM
如果你有更好的想法,请告诉我
If you know a better idea, please let me know
这篇关于AngularJS:如何格式化 ISO8601 日期格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!