0

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.

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

I would and have used used this approach.
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.