Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Invalid date from ISO format JS

I am getting the ISO date from an API call and this is the format

"2022-07-19T00:00:00.0000000Z"

when I try to convert this string into a date it gives "invalid date"

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

 var d = new Date(JSON.stringify(response[x]['time_start']));

what could be the issue? i tried solutions from similar questions but still no luck, any help would be greatly appreciated.

>Solution :

As per comment answer: just remove JSON.stringify.

const dateString = "2022-07-19T00:00:00.0000000Z";
 
// Valid:
const d = new Date(dateString); // Tue Jul 19 2022 03:00:00 GMT+0300 ...

// Invalid:
const jsonDate = JSON.stringify(dateString); // ""2022-07-19T00:00:00.0000000Z""
const d1 = new Date(jsonDate); // Invalid Date
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading