A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/javascript/javascript-date-tolocaledatestring-method/ below:

JavaScript Date toLocaleDateString() Method - GeeksforGeeks

JavaScript Date toLocaleDateString() Method

Last Updated : 11 Jul, 2025

The toLocaleDateString() method in JavaScript is used to convert the date and time of a Date object to a string representing the date portion using the locale-specific conventions.

Syntax:
dateObj.toLocaleDateString( [locales][, options])
Parameters:

This method accepts two parameters as mentioned above and described below:

Return values:

Note: The dateObj should be a valid Date object.

Example 1: Formatting Date with JavaScript's toLocaleDateString()

The code initializes a Date object and options for formatting. It then demonstrates the use of toLocaleDateString() to output the current date in different formats based on locale settings, with and without custom options.

JavaScript
let dateObj = new Date();
let options = {
    weekday: "long",
    year: "numeric",
    month: "short",
    day: "numeric"
};
console.log(dateObj.toLocaleDateString("en-US"));
console.log(dateObj.toLocaleDateString("en-US", options));

Output
3/14/2024
Thursday, Mar 14, 2024

Example 2: Without parameters return value of this method cannot be relied upon in scripting. It uses the operating system's locale conventions. 

JavaScript
let dateObj = new Date(1993, 6, 28, 14, 39, 7);
console.log(dateObj.toLocaleDateString());

Note: The locales and options arguments are not supported in all browsers. To check whether it is supported or not we can use the following function:

function toLocaleDateStringSupportsLocales() {
try {
new Date().toLocaleDateString('i');
}
catch (e) {
return e.name === 'RangeError';
}
return false;
}

We have a complete list of Javascript Date Objects, to check those please go through this Javascript Date Object Complete reference article.

Supported Browsers: What are some common pitfalls when using toLocaleDateString()?


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4