本文介绍了AngularJS:如何格式化ISO8601日期格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用,并使用ISO8601日期时间格式为 YYYY-MM- DDTHH:二:SSZ 作为他们的选择部分中提到

I am using bootstrap-datetimepicker and using ISO8601 datetime format as yyyy-mm-ddThh:ii:ssZ as mentioned in their options section

在我的控制器,我

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

在我的模板,我

<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

但作为每,它应该是为格式十月28,2010下午8时40分23秒

什么是我失踪?

推荐答案

现在,我已经创建了一个过滤器

For now, I have created a filter

angular.module('customFilters', []).
  filter('dateInMillis', function() {
    return function(dateString) {
      return Date.parse(dateString);
    };
  });

添加为依赖于 app.js

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 是presents日期

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日期格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-05 05:10