JavaScript Date toJSON() Method

Definition and Usage

toJSON() The method converts a Date object to a string in the format of JSON date.

The format of JSON date is the same as the ISO-8601 standard: YYYY-MM-DDTHH:mm:ss.sssZ

Example

Returns a Date object as a string in the format of JSON date:

var d = new Date();
var n = d.toJSON();

Try It Yourself

Syntax

Date.toJSON()

Parameters

No parameters.

Technical Details

Return Value: A string representing the date and time formatted as a JSON date.
JavaScript Version: ECMAScript 5

Browser Support

The numbers in the table indicate the first browser version that fully supports this method.

Method Chrome IE Firefox Safari Opera
toJSON() Support 9 Support Support Support

Related Pages

Tutorial:JavaScript Date

Tutorial:JavaScript Date Format

Tutorial:JSON Introduction