Skip to content
    Back to all guides
    Timestamps9 min read6/24/2026

    ISO 8601 Dates in JSON APIs: Formatting Rules That Prevent Bugs

    Use ISO 8601 correctly in JSON APIs: UTC vs offsets, fractional seconds, date-only pitfalls, and Unix timestamp interoperability.

    Quick answer

    Use ISO 8601 instants with explicit UTC (Z) or numeric offsets. Store UTC, convert to local time only for display, and document seconds vs milliseconds for Unix fields.

    Key takeaways

    • Always include Z or a numeric offset on datetime strings in JSON.
    • Date-only values are calendar dates, not UTC instants.
    • Pick one fractional-second precision per API field.
    • Use the Timestamp Converter to debug production log values.

    Apply this guide with the Timestamp Converter

    Open Timestamp Converter

    API bugs from date strings are painfully common: missing timezone, ambiguous local times, and mixed precision across services. ISO 8601 is the standard format most JSON APIs should use for instants — and the Timestamp Converter helps verify conversions when debugging payloads.

    What ISO 8601 looks like in JSON

    Common instant formats:

    json
    {
      "createdAt": "2026-06-24T14:30:00Z",
      "updatedAt": "2026-06-24T14:30:00.123Z",
      "scheduledFor": "2026-06-24T09:00:00-05:00"
    }
    PartMeaning
    TSeparates date and time
    ZUTC (Zulu) — zero offset
    -05:00Explicit offset from UTC
    .123Fractional seconds (milliseconds)

    Avoid ambiguous local strings without offset: "2026-06-24 14:30:00" — parsers may assume server local time.

    ISO 8601 vs Unix timestamps in APIs

    ISO 8601 stringUnix timestamp
    Human readableYesNo (integer)
    Timezone explicitYes (with Z or offset)Always UTC instant
    Sorting as stringWorks if same precision + UTC ZNatural numeric sort
    JSON sizeLargerSmaller
    JS parsingnew Date(iso)new Date(ms) — watch seconds vs ms

    Many APIs expose both for convenience. Document which field is canonical.

    Rules that prevent bugs

    1. Store UTC; show local only in UI

    javascript
    // API response (UTC)
    const createdAt = '2026-06-24T18:30:00Z';
    
    // Display in user locale
    new Intl.DateTimeFormat('en-US', {
      dateStyle: 'medium',
      timeStyle: 'short',
      timeZone: 'America/Chicago',
    }).format(new Date(createdAt));

    2. Always include offset or Z

    text
    Good: 2026-06-24T14:30:00Z
    Good: 2026-06-24T14:30:00+00:00
    Risky: 2026-06-24T14:30:00        (no zone — parser-dependent)

    3. Pick one fractional precision

    Mixing 2026-06-24T14:30:00Z and 2026-06-24T14:30:00.123Z in the same API is fine if documented. Comparisons and equality tests break when clients strip milliseconds inconsistently.

    4. Do not confuse date-only with instant

    json
    { "birthDate": "1990-05-15" }

    Date-only values are calendar dates, not moments in time. Do not convert them through timezone offsets for "midnight UTC" unless that is an explicit business rule.

    5. Seconds vs milliseconds in Unix fields

    If you also expose createdAtUnix, state whether it is seconds or milliseconds. Mixing them is a top-10 API bug.

    Use the Timestamp Converter to check a suspicious value both ways.

    JavaScript parsing examples

    javascript
    // ISO instant
    const d1 = new Date('2026-06-24T14:30:00Z');
    
    // With offset
    const d2 = new Date('2026-06-24T09:30:00-05:00'); // same instant as d1
    
    // Serialize back to ISO (UTC)
    d1.toISOString(); // '2026-06-24T14:30:00.000Z'
    javascript
    // WRONG: parsing date-only as UTC midnight for all users
    new Date('1990-05-15').toISOString(); // previous-day evening in US timezones

    Common ISO 8601 mistakes in APIs

    MistakeConsequence
    Omitting Z or offsetOff-by-hours bugs across regions
    Sending local time without offsetDouble timezone conversion
    Using MM/DD/YYYY in JSONLocale-dependent, not ISO
    Storing strings in non-UTC DB columnsDST and migration pain
    10-digit Unix in a field documented as msDates in 1970

    How to use ByteToolBox Timestamp Converter

    1. Open Timestamp Converter
    2. Paste an ISO 8601 string or Unix value from your API payload
    3. Confirm the human-readable instant matches expectations
    4. Toggle seconds vs milliseconds when debugging legacy fields

    Pair with Unix Timestamp Cheat Sheet for epoch conversion details.

    Related tools

    Try Timestamp Converter

    Paste a confusing API timestamp into the Timestamp Converter before you ship the fix.

    Related tools

    Related guides

    Frequently asked questions

    Last updated 6/24/2026