// Localized Date Formatting
// Current date/time
const now = new Date();
// 1. Localized date using the system locale
console.log("--- Using system locale ---");
console.log("Short date :", new Intl.DateTimeFormat(undefined).format(now));
console.log("Long date :", new Intl.DateTimeFormat(undefined, {
dateStyle: "full"
}).format(now));
console.log("Time :", new Intl.DateTimeFormat(undefined, {
timeStyle: "medium"
}).format(now));
console.log("Weekday :", new Intl.DateTimeFormat(undefined, {
weekday: "long"
}).format(now));
console.log("Month name :", new Intl.DateTimeFormat(undefined, {
month: "long"
}).format(now));
// 2. Localized date using a specific locale (example: French)
const locale = "fr-FR";
console.log("\n--- Using French locale ---");
console.log("Short date :", new Intl.DateTimeFormat(locale).format(now));
console.log("Long date :", new Intl.DateTimeFormat(locale, {
dateStyle: "full"
}).format(now));
console.log("Weekday :", new Intl.DateTimeFormat(locale, {
weekday: "long"
}).format(now));
console.log("Month name :", new Intl.DateTimeFormat(locale, {
month: "long"
}).format(now));
// 3. Custom localized pattern (weekday + day + month + year + time)
console.log("\n--- Custom French format ---");
console.log(
new Intl.DateTimeFormat(locale, {
weekday: "short",
day: "numeric",
month: "long",
year: "numeric",
hour: "2-digit",
minute: "2-digit"
}).format(now)
);
/*
run:
--- Using system locale ---
Short date : 4/19/2026
Long date : Sunday, April 19, 2026
Time : 2:07:16 PM
Weekday : Sunday
Month name : April
--- Using French locale ---
Short date : 19/04/2026
Long date : dimanche 19 avril 2026
Weekday : dimanche
Month name : avril
--- Custom French format ---
dim. 19 avril 2026 à 14:07
*/