Angular ng-repeat date formatting

夙愿已清 提交于 2019-12-11 01:56:16

问题


I am using angular ng-repeat to display an array of data including some columns which are dates but what is the best way to format the dates so they are presentable to the user? Thank you in advance.

DATES LOOK LIKE THIS IN VIEW 2016-01-14T08:00:00.000Z

WANT THIS FORMAT January 14, 2016

<td width="65%" class="joinedDate">{{user.created_at}}</td>

回答1:


if you format like your date (January 14, 2016) you can use

<td width="65%" class="joinedDate">{{user.created_at | date:'MMMM dd, yyyy'  }}</td>

OR

using date : 'medium' default date time like Oct 29, 2010 9:10:23 AM

<td width="65%" class="joinedDate">{{user.created_at |date:'medium'}}</td>

for more know https://docs.angularjs.org/api/ng/filter/date




回答2:


You can use date filter

Try like this

<td width="65%" class="joinedDate">{{user.created_at | date:'MMM dd, yyyy'  }}</td>

DEMO




回答3:


Below are some samples:

 <span ng-non-bindable>{{1288323623006 | date:'medium'}}</span>:
 <span>{{1288323623006 | date:'medium'}}</span><br>
 <span ng-non-bindable>{{1288323623006 | date:'yyyy-MM-dd HH:mm:ss Z'}}</span>:
 <span>{{1288323623006 | date:'yyyy-MM-dd HH:mm:ss Z'}}</span><br>
 <span ng-non-bindable>{{1288323623006 | date:'MM/dd/yyyy @ h:mma'}}</span>:
 <span>{{'1288323623006' | date:'MM/dd/yyyy @ h:mma'}}</span><br>
 <span ng-non-bindable>{{1288323623006 | date:"MM/dd/yyyy 'at' h:mma"}}</span>:
 <span>{{'1288323623006' | date:"MM/dd/yyyy 'at' h:mma"}}</span>

See this for more.

Hope it helps




回答4:


here is more about date filter

<td width="65%" class="joinedDate">{{ user.created_at | date:'MMMM dd, yyyy'}}</td>


来源:https://stackoverflow.com/questions/34805167/angular-ng-repeat-date-formatting

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!