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()
JavaScript
x
6
1
console.log(new Date().toString())
2
console.log(new Date().toISOString())
3
4
// To create it from string
5
const dateStr = "Fri Apr 20 2020 00:00:00 GMT+0530 (India Standard Time)"
6
console.log(new Date(dateStr).toISOString())