Readable dates with toLocaleDateString
const d = new Date(2026, 5, 30);
console.log(d.toLocaleDateString("en-GB")); // 30/06/2026
console.log(d.toLocaleDateString("en-US")); // 6/30/2026
Note that months are zero-based when you build a date, so 5 means June.
Control the output with options
const opts = { year: "numeric", month: "long", day: "numeric" };
console.log(d.toLocaleDateString("en-US", opts));
// June 30, 2026
The options object lets you choose long month names, weekdays, and more without manual string building.
ISO format for storage and APIs
console.log(new Date().toISOString());
// 2026-06-30T10:15:00.000Z
ISO strings sort correctly and are the right choice for databases and network requests.
Build a custom format by hand
const yyyy = d.getFullYear();
const mm = String(d.getMonth() + 1).padStart(2, "0");
const dd = String(d.getDate()).padStart(2, "0");
console.log(yyyy + "-" + mm + "-" + dd); // 2026-06-30
Common mistakes
- Forgetting months are zero-based. January is
0, December is11. - Not zero-padding. Use
padStart(2, "0")for single-digit days and months. - Storing localized strings. Save ISO and format only when displaying.
Frequently asked questions
Why is my month off by one?
JavaScript months run from 0 to 11, so getMonth() returns one less than you expect. Add 1 when displaying it.
Do I need a library like Moment.js?
Usually not. toLocaleDateString with options and Intl.DateTimeFormat handle most formatting needs natively.
Learn dates and built-in objects in our free JavaScript course.