Archive

Posts Tagged ‘date formatting’

Angular JS: date formatting in ng-repeat

Hi Friends,

I was binding some data using angular JS with ng-repeat, in my case there are couple of columns which are dates. From the data source it is coming in different format something like full date as 2017-04-21T09:01:00.000Z

Now I wanted to format it without changing my data source array, one option would be to create a JavaScript Date object and then convert in required format and then update the value in array.

Angular have some easy way to achieve date formatting with ng-repeat.

<div class="dateCreated">{{myobj.CreatedDate | date:'M/d/yy h:mm a'}}</div>

Or we can use fixed formats provided by Angular like ‘short’ or ‘mediumDate’, example

<div class="dateCreated">{{myobj.CreatedDate | date:'short'}}/div>

There are some other formats also available, please refer Angular Date formatting API documentation at https://docs.angularjs.org/api/ng/filter/date

Happy learning!

Advertisements