JavaScript toJSON()Method

Date 对象参考手册JavaScript Date Object

Example

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

var d=new Date();
var n=d.toJSON();

nOutput:


Try it Yourself »

Definition and Usage

The toJSON() method converts a Date object into a string, formatted 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 A date in JSON data format

Technical Details

JavaScript Version: 1.8.5


Date 对象参考手册JavaScript Date Object

Other Extensions