JavaScript Date toLocaleDateString()
Syntax & Examples


toLocaleDateString() method

The toLocaleDateString() method returns a string with a locality-sensitive representation of the date portion of this date based on system settings.


Syntax of toLocaleDateString()

There are 3 variations for the syntax of Date.toLocaleDateString() method. They are:

1.
toLocaleDateString()

This method returns a string representing the date portion of this date according to the default locale and options.

Returns value of type String.

2.
toLocaleDateString(locales)

Parameters

ParameterOptional/RequiredDescription
localesoptionalA string with a BCP 47 language tag, or an array of such strings, to specify the locale or locales.

This method returns a string representing the date portion of this date according to the specified locale.

Returns value of type String.

3.
toLocaleDateString(locales, options)

Parameters

ParameterOptional/RequiredDescription
localesoptionalA string with a BCP 47 language tag, or an array of such strings, to specify the locale or locales.
optionsoptionalAn object with configuration options for date formatting, such as weekday, year, month, day, etc.

This method returns a string representing the date portion of this date according to the specified locale and formatting options.

Returns value of type String.



✐ Examples

1 Using toLocaleDateString() method with no arguments

In JavaScript, we can use the toLocaleDateString() method to get the date portion of a date according to the default locale.

For example,

  1. Create a new Date object with the current date and time.
  2. Use the toLocaleDateString() method with no arguments.
  3. Log the resulting string to the console using console.log().

JavaScript Program

const date = new Date();
const localeDateString = date.toLocaleDateString();
console.log(localeDateString);

Output

Expected output: A string representing the date portion of the current date in the default locale format.

2 Using toLocaleDateString() method with a locale argument

In JavaScript, we can use the toLocaleDateString() method to get the date portion of a date in a specified locale.

For example,

  1. Create a new Date object with the current date and time.
  2. Use the toLocaleDateString() method with the locale argument 'en-GB' (English - United Kingdom).
  3. Log the resulting string to the console using console.log().

JavaScript Program

const date = new Date();
const localeDateString = date.toLocaleDateString('en-GB');
console.log(localeDateString);

Output

Expected output: A string representing the date portion of the current date in 'en-GB' locale format (e.g., '31/05/2024').

3 Using toLocaleDateString() method with locale and options arguments

In JavaScript, we can use the toLocaleDateString() method to get the date portion of a date in a specified locale with specific formatting options.

For example,

  1. Create a new Date object with the current date and time.
  2. Use the toLocaleDateString() method with the locale argument 'en-US' (English - United States) and options for weekday, year, month, and day.
  3. Log the resulting string to the console using console.log().

JavaScript Program

const date = new Date();
const options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' };
const localeDateString = date.toLocaleDateString('en-US', options);
console.log(localeDateString);

Output

Expected output: A string representing the date portion of the current date in 'en-US' locale format with specified options (e.g., 'Friday, May 31, 2024').

Summary

In this JavaScript tutorial, we learned about toLocaleDateString() method of Date: the syntax and few working examples with output and detailed explanation for each example.