0

I know that json does not treat dates in a special way and provides them as strings from the server.

The problem isn't converting the string into a date, but doing it manually for several fields and classes.

So, is there anyway to transform it to JS dates without having to format the date in every each request by iterating the json response and modifying the object ?

can I do this with the date-fns library ?

Adam chan
  • 1
  • 4

1 Answers1

0

You can use an Interceptor which would parse your chosen JSON responses and try to convert every field of these responses into a date using this. Bonne chance.

  • thank's for your reply, but why use an http interceptor to modify the data ? Doesn't seem like an Angular best practice to me. Is there any other method or solution to solve this problem ? – Adam chan Jul 14 '23 at 09:47
  • Create a class, which returns all fields from the response, then add method of this class, which will format date and returns it – yourBadApple Jul 14 '23 at 10:06