在 AngularJS 中格式化日期时间 [英] Format Date time in AngularJS
本文介绍了在 AngularJS 中格式化日期时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在 AngularJS 中正确显示日期和时间?
How do I properly display the date and time in AngularJS?
下面的输出显示了输入和输出,有和没有 AngularJS 日期过滤器:
The output below shows both the input and the output, with and without the AngularJS date filter:
In: {{v.Dt}}
AngularJS: {{v.Dt | date:'yyyy-MM-dd HH:mm:ss Z'}}
打印:
In: 2012-10-16T17:57:28.556094Z
AngularJS: 2012-10-16T17:57:28.556094Z
所需的显示格式是2010-10-28 23:40:23 0400
或 2010-10-28 23:40:23 EST
The desired display format is
2010-10-28 23:40:23 0400
or 2010-10-28 23:40:23 EST
推荐答案
v.Dt 可能不是 Date() 对象.
v.Dt is likely not a Date() object.
参见 http://jsfiddle.net/southerd/xG2t8/
但在您的控制器中:
scope.v.Dt = Date.parse(scope.v.Dt);
这篇关于在 AngularJS 中格式化日期时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文