Home  Postgress   How date is ...

How date is stored in JSON

Normal JSON (JavaScript Object Notation) does not have a built-in or native data type for dates or times.

Because the JSON standard only defines six basic types (string, number, object, array, boolean, and null), dates must be represented using one of these existing types.

In practice, dates are almost universally stored as a string or a number.


1. Primary Method: ISO 8601 String 📅

The most common, recommended, and interoperable way to store a date in JSON is as an ISO 8601 formatted string.

This format is language-agnostic, human-readable, and unambiguous because it explicitly includes time zone information (or indicates UTC).

Format TypeExampleDescription
Date-Time"2025-09-30T17:52:51.000Z"The most complete form, including the date, time, and the "Z" (Zulu/UTC) time zone indicator.
Date Only"2025-09-30"For fields that only require the calendar date.
Offset"2025-09-30T17:52:51+01:00"Includes a time zone offset from UTC.

Why ISO 8601 is Recommended:


2. Alternative Method: Unix Timestamp (Number) ⏳

The second common method is to use a JSON number to store the date as a Unix timestamp (also called Epoch Time).

Format TypeExampleDescription
Milliseconds1664521971000The number of milliseconds elapsed since the Unix Epoch (January 1, 1970, 00:00:00 UTC). This is preferred.
Seconds1664521971The number of seconds elapsed since the Unix Epoch.

Pros and Cons of Unix Timestamps:

Published on: Sep 30, 2025, 07:56 AM  
 

Comments

Add your comment