How do you format a Date object into custom readable strings in JavaScript?
Use the built-in **Intl.DateTimeFormat** API (or .toLocaleDateString()) for localized, zero-dependency date formatting, or extract parts manually using padStart(2, “0”)for strictYYYY-MM-DD` strings.
Modern Intl.DateTimeFormat (Recommended)
const now = new Date();
const formatted = new Intl.DateTimeFormat("en-US", {
year: "numeric",
month: "short",
day: "2-digit"
}).format(now);
console.log(formatted); // e.g., "Nov 19, 2026"
Custom YYYY-MM-DD Format
const year = now.getFullYear();
const month = String(now.getMonth() + 1).padStart(2, "0");
const day = String(now.getDate()).padStart(2, "0");
console.log(`${year}-${month}-${day}`); // "2026-11-19" '
You must log in or register to comment.
