Converting JSON Date Results into JavaScript Dates

Last Updated : 10 Sep, 2026

JSON data can contain dates in different formats. Modern APIs commonly return dates in the ISO 8601 format, while some older APIs and serializers use timestamp-based formats such as /Date(1559083200000)/.

  • Use the Date constructor directly for ISO 8601 date strings.
  • Extract the timestamp when working with the older /Date(timestamp)/ format.
  • JavaScript converts the provided date value into a Date object.

Approach 1: Using the Date Constructor with an ISO 8601 Date

Modern APIs commonly return dates in ISO 8601 format, such as "2026-09-09T10:30:00Z". JavaScript can directly convert this string into a Date object using the Date constructor.

html
<!DOCTYPE html>
<html>

<head>
    <title>
        Convert JSON Date to JavaScript Date
    </title>
</head>

<body>

    <h2>
        Convert JSON Date to JavaScript Date
    </h2>

    <p id="input"></p>

    <button onclick="convertDate()">
        Convert Date
    </button>

    <p id="output"></p>

    <script>
        const jsonDate = "2026-09-09T10:30:00Z";

        document.getElementById("input").textContent =
            "JSON Date: " + jsonDate;

        function convertDate() {

            const date = new Date(jsonDate);

            document.getElementById("output").textContent =
                "JavaScript Date: " + date;
        }
    </script>

</body>

</html>

Output:

Approach 2: Extracting a Timestamp from a Legacy JSON Date Format

Some older JSON serializers use the /Date(timestamp)/ format. In this approach, the numeric timestamp is extracted from the string and then passed to the Date constructor.

html
<h1 style="color:green;">
    GeeksforGeeks
</h1>

<p id="GFG_UP">
</p>

<button onclick="gfg_Run()">
    click here
</button>

<p id="GFG_DOWN">
</p>

<script>
    var el_up = document.getElementById("GFG_UP");
    var el_down = document.getElementById("GFG_DOWN");
    var jsonDate = '/Date(1559083200000)/';
    
    el_up.innerHTML = "Click on the button to convert"
                + " JSON result to JavaScript Date."
                + "<br>JSON Date - " + jsonDate;
    
    function gfg_Run() {
        var date = new Date(jsonDate.match(/\d+/)[0] * 1);
        el_down.innerHTML = date;
    }        
</script>

Output:

Note: ISO 8601 is the preferred date format for modern APIs because JavaScript can parse it directly using new Date(). The /Date(timestamp)/ format is mainly encountered when working with older systems or legacy JSON serializers.

Comment