The toLocaleDateString() method in JavaScript allows you to format a Date object into a localized string representing the date portion. The output format depends on the locale and implementation of the JavaScript engine. Here is a list of common date formats you may encounter when using toLocaleDateString():

  1. "6/17/2023" - This format represents the date in "short" format with the month, day, and year separated by slashes.

  2. "June 17, 2023" - This format represents the date with the full month name, followed by the day and year.

  3. "Jun 17, 2023" - This format represents the date with the abbreviated month name, followed by the day and year.

  4. "Saturday, June 17, 2023" - This format represents the date with the full weekday name, followed by the full month name, day, and year.

  5. "Sat, Jun 17, 2023" - This format represents the date with the abbreviated weekday name, followed by the abbreviated month name, day, and year.

  6. "17 June 2023" - This format represents the date with the day, full month name, and year.

  7. "17 Jun 2023" - This format represents the date with the day, abbreviated month name, and year.

Please note that the specific formats may vary depending on the browser, operating system, and the locale settings of the user's machine. To obtain the localized date format for a specific locale, you can execute the following code:

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

In the code above, the toLocaleDateString() method is called with the desired locale (in this case, 'en-US') and the formatting options specified by the options object. Adjust the locale and options according to your requirements.

Keep in mind that the list above covers some common formats, but there may be additional variations and localized formats based on specific locales and JavaScript engine implementations.

Have questions or queries?
Get in Touch