Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

JavaScript toJSON() Method

JavaScript toJSON() Method

Date Object Reference JavaScript Date object

Example

Returns a Date object as a string, formatted as JSON data:

var d=new Date();

var n=d.toJSON();

n Output result:

Try it »


Definition and Usage

The toJSON() method converts a Date object to a string and formats it as JSON data.

JSON data uses the same format as the ISO-8601 standard: YYYY-MM-DDTHH:mm:ss.sssZ


Browser support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the toJSON() method

Note: Internet Explorer 8 and earlier IE versions do not support this method.


Syntax

Date

.toJSON()

Return Value

Type Description
String Date in JSON data format

Technical Details

JavaScript version: 1.8.5

Date Object Reference JavaScript Date object