Javascript - Date toJSON() Method

The toJSON() method converts a Date object a JSON date in string.

Description

The toJSON() method converts a Date object a JSON date in string.

JSON dates use the the ISO-8601 standard format: YYYY-MM-DDTHH:mm:ss.sssZ

Syntax

Date.toJSON()

Return

A String, representing the date and time formatted as a JSON date

Example

Return a Date object as a String, formatted as a JSON date:

Demo

//display the date and time as a string, formatted as a JSON date.

var d = new Date();
var n = d.toJSON();
console.log(n);/*from  w  ww .  j  a v  a2  s  . c  om*/

Result