I have a Date format like this "Fri Apr 20 2020 00:00:00 GMT+0530 (India Standard Time)"
I want to convert that above format to this format 2020-04-20T00:00:00.000Z
Actually I tried this JSON.stringify(new Date("Fri Apr 20 2020 00:00:00 GMT+0530 (India Standard Time)"))
while using this am getting the output one day before 2020-04-19T18:30:00.000Z
so please anyone help me to convert this date format "Fri Apr 20 2020 00:00:00 GMT+0530 (India Standard Time)"
like this 2020-04-20T00:00:00.000Z
Thanks in Advance.
Advertisement
Answer
Your date seems to be a standard string representation of new Date()
, you can get the desired format by using new Date().toISOString()
console.log(new Date().toString()) console.log(new Date().toISOString()) // To create it from string const dateStr = "Fri Apr 20 2020 00:00:00 GMT+0530 (India Standard Time)" console.log(new Date(dateStr).toISOString())