I am using MongoDB to store data, and on retrieving them I want to get the date and convert it to something that looks like this:
'2022-07-20T10:12:21.054Z'
right now my date looks like this:
"Nov. 13, 2022 at 5:51 AM "
because I am getting it directly from mongo through the createdAt key. How can I achieve this?
2
Answers
Try this: (You may need to define your time zone to get this right)
Looks like
new Date(`${yyyy}-${mmm}-${dd} ${time}`)
this format may not be supported, build an array for Month format matching or add a switch function could be a choice: