Reputation: 4232
Retrieving a large JSON data object from an API, a lot of which needs to be rendered for the view.
There are numerous date fields nested throughout the object, all of which are in milliseconds.
These are required to be converted to a date object for the view.
What is the most pragmatic approach to achieve this?
Is it simply to loop over the object and call getTime() on each of the date fields, or is there something a little more cleaner?
Any advice would be much appreciated.
Upvotes: 0
Views: 50
Reputation: 91
Why not just put them in the view with Angular's date-filter?
<div>{{yourDate | date}}</div>
The filter accepts time in milliseconds (string or number) and can output to a lot of formats.
Upvotes: 0
Reputation: 1571
You can use an angular $http interceptor which to parse and automatically convert your date strings in to date objects.
This tutorial should point you in the right direction http://blog.baltrinic.com/software-development/web-development/angularjs-http-interceptor-date-conversion
Upvotes: 1