Web/JavaScript/Reference/Global objects/Date/toJSON

From Get docs


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

Update compatibility data on GitHub

Desktop Mobile Server
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet Node.js
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


See also