JavaScript toJSON()

The JavaScript date toJSON() method is used to get a string representing the Date object and serializing the Date object at the time of JSON serialization.

Syntax:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
dateObj.toJSON();
dateObj.toJSON();
dateObj.toJSON();

Return:
String representation of the date portion of a Date object.

Example:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<!DOCTYPE html>
<html>
<body>
<script>
var bday=new Date("November 16, 1994 21:10:10");
document.writeln(bday.toJSON());
</script>
</body>
</html>
<!DOCTYPE html> <html> <body> <script> var bday=new Date("November 16, 1994 21:10:10"); document.writeln(bday.toJSON()); </script> </body> </html>
<!DOCTYPE html>
<html>
<body>
<script>
var bday=new Date("November 16, 1994 21:10:10");
document.writeln(bday.toJSON());
</script>
</body>
</html>