Skip to content

The “right” JSON Date Format

JSON is a prominent serialization format. For web-based applications, it has become the standard. However, JSON itself does not specify how dates should be represented.

In JavaScript, dates are serialized as ISO 8601 strings. When JSON.stringify encounters a Date object, it automatically calls its toJSON method, which returns an ISO 8601 string. This string is treated like any other string during serialization and deserialization. While ISO 8601 is the standard for data interchange in JSON, the format itself does not include a built-in parser. To deserialize, you must explicitly convert the string back into a Date object using new Date() or Date.parse().

You should use the format emitted by JavaScript Date's toJSON method:

javascript format javascript date

javascript
"2020-03-09T22:18:26.625Z"

The date is represented in a standard and sortable format that represents a UTC time.

This is also the preferred representation according to ECMA using the JSON.stringify:

javascript format javascript date

Output appears here after Run.

ISO 8601 Format

ISO 8601 Format (International Organization for Standardization) is an international standard that covers the exchange of date and time-related data. This standard provides a well-defined method of representing dates and times, so as to avoid misinterpretation of numeric representations of dates and times.

Do you find this helpful?

Dual-run preview — compare with live Symfony routes.