目录

JavaScript Date toJSON()

Example

Get a date as a string, formatted as a JSON date:

const d = new Date();
let text = d.toJSON();
Try it Yourself »

Description

The toJSON() method returns a date object as a string, formatted as a JSON date.

JSON dates have the same format as the ISO-8601 standard: YYYY-MM-DDTHH:mm:ss.sssZ


Browser Support

toJSON() is an ECMAScript5 (ES5) feature.

ES5 (JavaScript 2009) fully supported in all browsers:

Chrome Edge Firefox Safari Opera IE
Yes Yes Yes Yes Yes 9-11

Syntax

Date.toJSON()

Parameters

None

Technical Details

Return Value: A String, representing the date and time formated as a JSON date
JavaScript Version: ECMAScript 5