Blog hero image
random

Common date format

YYYY-MM-DD

By Coolemur
2024-12-14

The most widely used date format, and the official international standard, is YYYY-MM-DD. This format is recommended by the International Organization for Standardization (ISO 8601).

However, every user interface (UI) should respect the user’s locale. When a user selects a different language, the displayed date formats should adapt accordingly.

JavaScript Examples: Date Formatting by Locale

Here are some examples of how date formats change based on locale settings in JavaScript:

// Example 1: Default Locale
const date = new Date("2024-12-14");
console.log(date.toLocaleDateString());
// Output (depending on system locale): "12/14/2024" (US) or "14/12/2024" (UK)

// Example 2: Specific Locale - US
console.log(date.toLocaleDateString("en-US"));
// Output: "12/14/2024"

// Example 3: Specific Locale - UK
console.log(date.toLocaleDateString("en-GB"));
// Output: "14/12/2024"

// Example 4: Specific Locale - Japan
console.log(date.toLocaleDateString("ja-JP"));
// Output: "2024/12/14"

// Example 5: Adding Options
console.log(
  date.toLocaleDateString("en-US", {
    weekday: "long",
    year: "numeric",
    month: "long",
    day: "numeric",
  })
);
// Output: "Saturday, December 14, 2024" (US)

console.log(
  date.toLocaleDateString("fr-FR", {
    weekday: "long",
    year: "numeric",
    month: "long",
    day: "numeric",
  })
);
// Output: "samedi 14 décembre 2024" (France)

Note: The reason the ISO format is used on this site is that it is a tech-focused blog without locale selection. 👀

Conclusion

For developers, it’s essential to use ISO 8601 (YYYY-MM-DD) as the standard format for storing and processing dates. This ensures consistency and avoids errors caused by regional differences. When displaying dates to users, always adapt the format to their locale to provide a familiar and user-friendly experience.

Back