The toJSON()
method returns a string representation of the Date
object.
The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.
Syntax
dateObj.toJSON()
Return value
A string representation of the given date.
Description
Date
instances refer to a specific point in time. Calling toJSON()
returns a string (using toISOString()
) representing the Date
object's value. This method is generally intended to, by default, usefully serialize Date
objects during JSON serialization.
Examples
Using toJSON()
var jsonDate = (new Date()).toJSON(); var backToDate = new Date(jsonDate); console.log(jsonDate); //2015-10-26T07:46:36.611Z
Specifications
Specification |
---|
ECMAScript (ECMA-262) The definition of 'Date.prototype.toJSON' in that specification. |
Browser compatibility
The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Desktop | Mobile | Server | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
toJSON | Chrome Full support 3 | Edge Full support 12 | Firefox Full support 1 | IE Full support 8 | Opera Full support 10.5 | Safari Full support 5 | WebView Android Full support ≤37 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support 11 | Safari iOS Full support 4.2 | Samsung Internet Android Full support 1.0 | nodejs Full support 0.1.100 |
Legend
- Full support
- Full support