简体   繁体   English

从angular.js应用程序中的JSON返回的时间格式

[英]Time format returned from JSON in angular.js app

So I receive my app data via an API returning JSON data. 因此,我通过返回JSON数据的API接收了我的应用数据。 With that, my time stamps are always returned with an undesirable look. 这样,我的时间戳总是以不理想的外观返回。 Always like this: 总是这样:

2013-11-25T12:44:02 2013-11-25T12:44:02

So I am using angular to build my app and couldn't see a way to format this with simply returning something like: 所以我正在使用angular来构建我的应用程序,却看不到通过简单地返回类似以下内容来格式化它的方法:

<div>
    <p ng-repeat="date in ppt.Alerts | filter:{type: DenialStatement}"><span>{{date.date}}<span> <span>{{date.descr}}<span></p>
</div>

In this case, date is that time property. 在这种情况下, 日期是时间属性。 So I was figuring within my html, if I could benefit from using moment.js to format this or a better way to do this across the board. 因此,我想弄清楚自己的html中是否可以受益于使用moment.js格式化或更好地实现此目的。

Can anyone here assist with this? 这里有人可以协助吗?

Thanks much. 非常感谢。

Angular has built in date filter Angular内置了日期过滤器

{{date.date |  date : format : timezone}}

See date filter docs for format and timezone usage 请参阅日期过滤器文档以了解格式和时区使用情况

Your text is string representation of date object, you can assign date.date = new Date(input) during data retrieval this will work fine. 您的文本是日期对象的字符串表示形式,您可以在数据检索期间分配date.date = new Date(input) ,这将很好地工作。 And you can print directly angular built in date filter 您可以直接打印内置角度的日期过滤器

<span>{{date.date|date :'dd/MM/yyyy'}}<span>

or any format you prefer. 或您喜欢的任何格式。

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

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