Formatting Dates and Times
Display dates with Intl.DateTimeFormat.
Formatting Dates and Times is a free JavaScript Academy lesson on CoddyKit. This is lesson 2 of 4. Any 3 lessons of this learning path are free to read in full — after that, CoddyKit PRO unlocks every lesson, plus hands-on practice with a built-in code editor and a 24/7 AI tutor. It is part of the JavaScript Academy learning path, and your progress syncs across the web and the CoddyKit app. The JavaScript Academy course includes 4 lessons in total.
Intl.DateTimeFormat
Intl.DateTimeFormat formats Date objects according to a locale, replacing brittle manual string building.
const dtf = new Intl.DateTimeFormat("en-US");
console.log(dtf.format(new Date("2026-05-29"))); // "5/29/2026"Locale Differences
Date order differs by region: US is month/day/year, much of Europe is day/month/year.
const d = new Date("2026-05-29");
console.log(new Intl.DateTimeFormat("en-US").format(d)); // 5/29/2026
console.log(new Intl.DateTimeFormat("en-GB").format(d)); // 29/05/2026Date Style Presets
dateStyle offers "full", "long", "medium", "short" presets for quick, readable output.
const d = new Date("2026-05-29");
console.log(new Intl.DateTimeFormat("en-US", { dateStyle: "full" }).format(d));
// "Friday, May 29, 2026"Time Style
timeStyle works the same way for the time portion and can combine with dateStyle.
const d = new Date("2026-05-29T14:30:00");
console.log(new Intl.DateTimeFormat("en-US", { dateStyle: "medium", timeStyle: "short" }).format(d));
// "May 29, 2026, 2:30 PM"Custom Component Options
For fine control, specify components like year, month, day, weekday individually.
const d = new Date("2026-05-29");
const f = new Intl.DateTimeFormat("en-US", { weekday: "long", year: "numeric", month: "long", day: "numeric" });
console.log(f.format(d)); // "Friday, May 29, 2026"Month Formats
month accepts "numeric", "2-digit", "short", "long", and "narrow".
const d = new Date("2026-05-29");
console.log(new Intl.DateTimeFormat("en-US", { month: "long" }).format(d)); // "May"
console.log(new Intl.DateTimeFormat("en-US", { month: "short" }).format(d)); // "May"12 vs 24 Hour
hour12: true/false overrides the locale default for clock format.
const d = new Date("2026-05-29T20:05:00");
console.log(new Intl.DateTimeFormat("en-US", { hour: "numeric", minute: "2-digit", hour12: false }).format(d));
// "20:05"Time Zones
Pass a timeZone IANA name to render a date in any zone, independent of the runtime's local zone.
const d = new Date("2026-05-29T12:00:00Z");
console.log(new Intl.DateTimeFormat("en-US", { timeStyle: "long", timeZone: "Asia/Tokyo" }).format(d));formatToParts
formatToParts returns an array of typed tokens, letting you style or rearrange individual pieces.
const parts = new Intl.DateTimeFormat("en-US").formatToParts(new Date("2026-05-29"));
console.log(parts.map((p) => p.type + ":" + p.value).join(" "));Formatting Ranges
formatRange(start, end) renders a date range compactly, merging shared components.
const f = new Intl.DateTimeFormat("en-US", { month: "short", day: "numeric" });
console.log(f.formatRange(new Date("2026-05-01"), new Date("2026-05-05")));
// "May 1 – 5"Non-Gregorian Calendars
The calendar option supports systems like "islamic", "hebrew", or "japanese".
const d = new Date("2026-05-29");
console.log(new Intl.DateTimeFormat("en-US", { calendar: "japanese", dateStyle: "long" }).format(d));Quick Check
Test date formatting.
Recap: Dates and Times
You formatted dates and times with Intl.DateTimeFormat, used dateStyle/timeStyle presets and granular component options, handled time zones, 12/24-hour clocks, formatToParts, ranges, and alternate calendars. Next: relative time and plurals.
Learn JavaScript with an AI tutor — free
Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.
- Courses
- 59
- Lessons
- 200
Frequently Asked Questions
Is the “Formatting Dates and Times” lesson free?
Yes — any 3 lessons of the JavaScript Academy learning path, including “Formatting Dates and Times”, are free to read in full here on the web. After that, CoddyKit PRO unlocks every lesson, plus interactive practice with a built-in code editor and a 24/7 AI tutor. The JavaScript Academy course includes 4 lessons in total.
What will I learn in “Formatting Dates and Times”?
Display dates with Intl.DateTimeFormat. You practise JavaScript Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start JavaScript Academy?
No prior experience is required. JavaScript Academy on CoddyKit is structured for beginners through advanced learners, so you can start here or from the beginning and move at your own pace. This is lesson 2 of 4.
How long does the “Formatting Dates and Times” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this JavaScript Academy lesson?
Yes. Every JavaScript Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Formatting Numbers and Currency
- Formatting Dates and Times
- Relative Time and Plurals
- Locale-Aware Sorting