W3cubDocs

/JavaScript

date.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

Browser compatibilityUpdate compatibility data on GitHub

Desktop
Chrome Edge Firefox Internet Explorer Opera Safari
toJSON 3 12 1 8 10.5 5
Mobile
Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
toJSON ≤37 18 4 11 4.2 1.0
Server
Node.js
toJSON 0.1.100

See also

© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://wiki.developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toJSON