Topics in this subject
JavaScript 2 min read Updated 4 Aug 2026

Part 14 — Dates

Getting & formatting, Intl formatting 🟢, Temporal (the future) 🟢

Date is famously awkward; know its traps and reach for the modern option when possible.

new Date();                       // now
new Date("2025-01-31T10:00:00Z"); // ISO parse (safe)
new Date(2025, 0, 31);            // ⚠️ month is 0-indexed! → January
Date.now();                       // ms since epoch (number)

Getting & formatting#

const d = new Date();
d.getFullYear(); d.getMonth() /*0-11*/; d.getDate() /*1-31*/;
d.getDay();      // 0=Sunday
d.getHours(); d.getMinutes();
d.getTime();     // epoch ms
d.toISOString(); // "2025-01-31T10:00:00.000Z" (UTC)

⚠️ Traps: months are 0-indexed; getDay is weekday not date; parsing non-ISO strings is implementation-defined; Date is mutable.

Intl formatting 🟢#

new Intl.DateTimeFormat("en-IN", {
  dateStyle: "long", timeStyle: "short", timeZone: "Asia/Kolkata"
}).format(new Date());
// e.g. "31 January 2025 at 3:30 pm"

new Intl.RelativeTimeFormat("en").format(-1, "day"); // "yesterday"
new Intl.NumberFormat("en-IN", { style: "currency", currency: "INR" }).format(1234.5);
// "₹1,234.50"

Temporal (the future) 🟢#

The Temporal proposal fixes Date's design: immutable objects, explicit time zones, no 0-indexed months.

// Temporal.Now.plainDateISO();      → 2025-01-31
// Temporal.PlainDate.from("2025-01-31").add({ days: 5 });

Not yet universal at time of writing — use a polyfill, or a library (Luxon, date-fns, Day.js) for production date math today.

Interview questions (Part 14):

  1. Why is new Date(2025, 1, 1) February, not January?
  2. How do you format a date for a specific locale and time zone?
  3. What does Temporal improve over Date?