toLocaleDateString()

ES1+

Returns the date portion of the Date as a string, using locale conventions.

Syntax

date.toLocaleDateString(locales, options)

Parameters

locales string | Array optional

A string with a BCP 47 language tag

options Object optional

An object with configuration properties

Return Value

string

A string representing the date portion

Examples

JavaScript
const date = new Date('2024-01-15');
console.log(date.toLocaleDateString('ko-KR'));
console.log(date.toLocaleDateString('en-US', {
  weekday: 'long',
  year: 'numeric',
  month: 'long',
  day: 'numeric'
}));
Output:
// '2024. 1. 15.' 'Monday, January 15, 2024'

📌 When to Use

Use toLocaleDateString() when you need only the date portion (without time) in a localized format.

⚠️ Common Mistakes

Expecting consistent output across browsers without specifying locale and options.

✅ Best Practices

Specify options explicitly for consistent formatting: { year: "numeric", month: "long", day: "numeric" }.

⚡ Performance Notes

Same as toLocaleString() - use Intl.DateTimeFormat for repeated formatting operations.

🌍 Real World Example

Blog Post Date Display

Display blog post dates in a reader-friendly format based on locale.

function formatPostDate(dateString, locale = 'en-US') {
  const date = new Date(dateString);
  const now = new Date();
  const diffDays = Math.floor((now - date) / (1000 * 60 * 60 * 24));

  if (diffDays === 0) return 'Today';
  if (diffDays === 1) return 'Yesterday';
  if (diffDays < 7) return `${diffDays} days ago`;

  return date.toLocaleDateString(locale, {
    year: 'numeric',
    month: 'long',
    day: 'numeric'
  });
}

console.log(formatPostDate('2024-03-14')); // "Yesterday" or "March 14, 2024"

Related Methods