iwantcoding.com
🔥 Daily 👥 Rooms 🏆 Top Log in Sign up

JS Date Formats

JavaScript's Date understands a handful of input formats and produces several output formats. Sticking to ISO 8601 avoids almost every parsing surprise.

Input formats new Date(…) accepts

FormatExampleNotes
ISO 8601 (preferred)"2026-06-06T12:00:00Z"Always interpreted as UTC when ending in Z.
ISO date only"2026-06-06"Treated as UTC midnight.
RFC 2822"06 Jun 2026 12:00:00 GMT"Verbose, locale-sensitive.
Implementation-specific"06/06/2026"Avoid — varies by browser and locale.

Output formats

MethodReturns
d.toISOString()"2026-06-06T12:00:00.000Z" — machine-friendly.
d.toUTCString()"Sat, 06 Jun 2026 12:00:00 GMT"
d.toDateString()"Sat Jun 06 2026"
d.toTimeString()"12:00:00 GMT+0000"
d.toLocaleString(locale, opts)Localised — your everyday choice for display.
d.toJSON()Same as toISOString() — used by JSON.stringify.

Intl.DateTimeFormat — the modern way to display

JS
const fmt = new Intl.DateTimeFormat("en-US", {
  year: "numeric", month: "long", day: "numeric",
  hour: "2-digit", minute: "2-digit",
  timeZone: "America/New_York",
});
fmt.format(new Date());  // "June 6, 2026, 08:00 AM"

// Range formatting
new Intl.DateTimeFormat("en-US").formatRange(start, end);
Tip: Build the Intl.DateTimeFormat once and reuse it in a loop. It caches its locale data and is much faster than calling toLocaleString per row.

Example

Example
<!DOCTYPE html>
<html>
<body>

<p id="out"></p>

<script>
document.getElementById("out").textContent = "Hello from JS Date Formats!";
</script>

</body>
</html>
Try it Yourself »

Exercise

Produce the canonical machine-friendly date string.

const stamp = new Date(). ();

Test yourself

Q1. Most reliable date input format for new Date(…) is…
Q2. Modern locale-aware date formatting uses…
Q3. JSON.stringify(new Date()) calls…

Discussion

Loading…