Date.prototype.toJSON()

The toJSON() method returns a string representation of the Date object.

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

DesktopMobileServer
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung InternetNode.js
toJSONChrome Full support 3Edge Full support 12Firefox Full support 1IE Full support 8Opera Full support 10.5Safari Full support 5WebView Android Full support ≤37Chrome Android Full support 18Firefox Android Full support 4Opera Android Full support 11Safari iOS Full support 4.2Samsung Internet Android Full support 1.0nodejs Full support 0.1.100

Legend

Full support
Full support

See also