Here’s a handy snippet that you can use to convert a JavaScript date object to a date string or ISO date format (YYYY-MM-DDTHH:mm:ss.sssZ).

let date = new Date().toISOString()

console.log(date)
// 2024-10-08T20:00:04.040Z

Tagged in: