JavaScript toJSON()Method
Example
Returns the Date object as a string, formatted as JSON data:
var d=new Date();
var n=d.toJSON();
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
![]()
![]()
![]()
![]()
![]()
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 |
|---|
Other Extensions
JavaScript Date Object