The JavaScript toLocaleDateString function converts the Date portion of a given date to a string using the system locale conversion.
The syntax of the toLocaleDateString function is:
Date.toLocaleDateString(locales, options)
Parameters: It accepts two optional parameters.
- locale: Here, we can specify the language that the JavaScript toLocaleDateString function has to consider to convert the date portion. For example, en-US.
- options: Here, we can specify how the weekday, month, year, and day of the month should appear. For example, long weekday = Monday, whereas short = Mon.
Return Value: The toLocaleDateString method returns the string representation of the date portion of the given datetime according to the specified locale language.
JavaScript toLocaleDateString example
In the following example, we use the toLocaleDateString method without any parameter values. It means the function uses system locales to convert the date portion of today’s date to a string.
const dt = new Date();
console.log(dt);
console.log(dt.toLocaleDateString());
Tue Jun 16 2026 15:23:28 GMT+0530 (India Standard Time)
16/6/2026
Example 2: This JavaScript uses the Date() constructor to parse a custom date. Next, the toLocaleDateString method returns the custom date of a given date in a string format. Please refer to the toLocaleTimeString() for the time portion.
const dt = new Date(2005, 11, 14, 2, 19, 5);
console.log(dt);
console.log(dt.toLocaleDateString());
Wed Dec 14 2005 02:19:05 GMT+0530 (India Standard Time)
14/12/2005
Using locale in toLocaleDateString
By default, the toLocaleDateString() method uses the local system language for the string representation of a given date. However, we can change the language using the first parameter. The following example uses US English, so it shows dates in MM/dd/yyyy format.
const dt = new Date();
console.log(dt);
console.log(dt.toLocaleDateString("en-US"));
Tue Jun 16 2026 15:28:44 GMT+0530 (India Standard Time)
6/16/2026
Using options in JavaScript toLocaleDateString()
Along with locale, we can use options in the toLocaleDateString() method. If you observe the code below, we set the weekday and month as long. So, instead of showing Tue Jun, it displays as Tuesday and June.
const dt = new Date();
console.log(dt);
const options = {
weekday: "long",
year: "numeric",
month: "long",
day: "numeric",
};
console.log(dt.toLocaleDateString("en-US", options));
Tue Jun 16 2026 15:31:26 GMT+0530 (India Standard Time)
Tuesday, June 16, 2026
Format toLocaleDateString date to yyyy-MM-dd
By default, the toLocaleDateString() follows the local system language setting for the string representation of the date portion. Instead of writing a logic to convert the local date to yyyy-MM-dd, we can use languages like English Canada or “sv-SE”.
const dt = new Date();
console.log(dt);
console.log(dt.toLocaleDateString("en-CA"));
console.log(dt.toLocaleDateString("sv-SE"));
Tue Jun 16 2026 15:35:21 GMT+0530 (India Standard Time)
2026-06-16
2026-06-16