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 w w  . j  ava 2  s  .co  m*/

Result