Json date formatted[SOLVED]

i want to display the date of an article in a certain format.i used angularjs date filter but didn’t work.i believe the value isn’t recognised as date.the date is inside an object which inside an array of objects.
if there’s anyway to display that date.i used moment.js library and didn’t work.i believe the main problem ishow to convert the string to a date.
thank you

Can you post how it look the json (and the date string) and how you try to print that date?

here’s a look of the json file
as for what i do in the code i just display {{article.Article.date_pub}} which works.but i want to format it i tried {{article.Article.date_pub | date :‘short’}}

I think the problem is that the date is not a valid ISO format, try to convert it to ISO format and try again.
ISO format is like: 2017-01-30T12:25:55.000Z

So you can easily split your current string date by the empty space, added a “T” in the middle and “.000Z” at the end, example:

let dateArray = date_pub.split(" ");
date_pub = dateArray[0] + "T" + dateArray[1] + ".000Z";

You even can make a pipe to transform your current date value in a ISO date value, and concatenate this pipe with the angular Date pipe


ok.thanks for the answer and i’ll give it a try

i solved my problem using the angular filter.thanks @Adonai for the response anyway :smile: