Home >>JavaScript Date Object Methods >JavaScript toJSON() Method
JavaScript toJSON() method is used to convert a given Date object into a string formatted as a JSON date. The JSON dates have the same format as the ISO-8601 standard: YYYY-MM-DDTHH:mm:ss.sssZ.
Syntax:Date.toJSON()
Method | Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
toJSON() | Yes | 9 | Yes | Yes | Yes |
<html> <body> <p>Click the button to see the Output.</p> <button onclick="myFunction()">Try it</button> <p id="demo"></p> <script> function myFunction() { var d = new Date(); var n = d.toJSON(); document.getElementById("demo").innerHTML = n; } </script> </body> </html>
Click the button to see the Output.