How to useDate.toISOString() method in Javascript
The toISOString() method in JavaScript converts a Date object to a string in ISO 8601 format (YYYY-MM-DDTHH:mm:ss.sssZ). This format is widely accepted and used for representing dates and times.
Example: We will convert a Date object to a string using the toISOString() method.
// New date using date Constructor
let d = new Date();
// Convert to string
let dateString = d.toISOString();
// Print output
console.log(dateString);
Output
2024-05-23T12:37:36.005Z
JavaScript Program to Convert Date to String
In this article, we will see how to convert a JavaScript Date to a string using JavaScript. We have a few methods to convert JavaScript Date to string which are described below.