If you need slightly less control over formatting than the currently accepted answer, Date#toLocaleDateString can be used to create standard locale-specific renderings. The locale and options arguments let applications specify the language whose formatting conventions should be used, and allow some customization of the rendering.

Options key examples:

  1. day:
    The representation of the day.
    Possible values are "numeric", "2-digit".
  2. weekday:
    The representation of the weekday.
    Possible values are "narrow", "short", "long".
  3. year:
    The representation of the year.
    Possible values are "numeric", "2-digit".
  4. month:
    The representation of the month.
    Possible values are "numeric", "2-digit", "narrow", "short", "long".
  5. hour:
    The representation of the hour.
    Possible values are "numeric", "2-digit".
  6. minute: The representation of the minute.
    Possible values are "numeric", "2-digit".
  7. second:
    The representation of the second.
    Possible values are "numeric", 2-digit".
  8. hour12:
    The representation of time format.
    Accepts boolean true or false

All these keys are optional. You can change the number of options values based on your requirements, and this will also reflect the presence of each date time term.

Note: If you would only like to configure the content options, but still use the current locale, passing null for the first parameter will cause an error. Use undefined instead.

For different languages:

  1. "en-US": For American English
  2. "en-GB": For British English
  3. "hi-IN": For Hindi
  4. "ja-JP": For Japanese

You can use more language options.

For example

var options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' };
var today  = new Date();

console.log(today.toLocaleDateString("en-US")); // 9/17/2016
console.log(today.toLocaleDateString("en-US", options)); // Saturday, September 17, 2016
console.log(today.toLocaleDateString("hi-IN", options)); // शनिवार, 17 सितंबर 2016

You can also use the toLocaleString() method for the same purpose. The only difference is this function provides the time when you don't pass any options.

// Example
9/17/2016, 1:21:34 PM

References:

  • toLocaleString()

  • toLocaleDateString()

Answer from ajeet kanojia on Stack Overflow
🌐
W3Schools
w3schools.com › js › js_date_formats.asp
W3Schools.com
JS Examples JS HTML DOM JS HTML Input JS HTML Objects JS HTML Events JS Browser JS Editor JS Exercises JS Quiz JS Website JS Syllabus JS Study Plan JS Interview Prep JS Bootcamp JS Certificate JS Reference ... The ISO format follows a strict standard in JavaScript. The other formats are not so well defined and might be browser specific. Independent of input format, JavaScript will (by default) output dates in full text string format:
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date
Date - JavaScript | MDN
Furthermore, implementations are allowed to support other date formats when the input fails to match this format. The toISOString() method returns a string representation of the date in the date time string format, with the time zone offset always set to Z (UTC).
Top answer
1 of 16
3084

If you need slightly less control over formatting than the currently accepted answer, Date#toLocaleDateString can be used to create standard locale-specific renderings. The locale and options arguments let applications specify the language whose formatting conventions should be used, and allow some customization of the rendering.

Options key examples:

  1. day:
    The representation of the day.
    Possible values are "numeric", "2-digit".
  2. weekday:
    The representation of the weekday.
    Possible values are "narrow", "short", "long".
  3. year:
    The representation of the year.
    Possible values are "numeric", "2-digit".
  4. month:
    The representation of the month.
    Possible values are "numeric", "2-digit", "narrow", "short", "long".
  5. hour:
    The representation of the hour.
    Possible values are "numeric", "2-digit".
  6. minute: The representation of the minute.
    Possible values are "numeric", "2-digit".
  7. second:
    The representation of the second.
    Possible values are "numeric", 2-digit".
  8. hour12:
    The representation of time format.
    Accepts boolean true or false

All these keys are optional. You can change the number of options values based on your requirements, and this will also reflect the presence of each date time term.

Note: If you would only like to configure the content options, but still use the current locale, passing null for the first parameter will cause an error. Use undefined instead.

For different languages:

  1. "en-US": For American English
  2. "en-GB": For British English
  3. "hi-IN": For Hindi
  4. "ja-JP": For Japanese

You can use more language options.

For example

var options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' };
var today  = new Date();

console.log(today.toLocaleDateString("en-US")); // 9/17/2016
console.log(today.toLocaleDateString("en-US", options)); // Saturday, September 17, 2016
console.log(today.toLocaleDateString("hi-IN", options)); // शनिवार, 17 सितंबर 2016

You can also use the toLocaleString() method for the same purpose. The only difference is this function provides the time when you don't pass any options.

// Example
9/17/2016, 1:21:34 PM

References:

  • toLocaleString()

  • toLocaleDateString()

2 of 16
1756

For custom-delimited date formats, you have to pull out the date (or time) components from a DateTimeFormat object (which is part of the ECMAScript Internationalization API), and then manually create a string with the delimiters you want.

To do this, you can use DateTimeFormat#formatToParts. You could destructure the array, but that is not ideal, as the array output depends on the locale:

{ // example 1
   let formatter = new Intl.DateTimeFormat('en');
   let example = formatter.formatToParts();
   console.log(example);
}
{ // example 2
   let formatter = new Intl.DateTimeFormat('hi');
   let example = formatter.formatToParts();
   console.log(example);
}

Better would be to map a format array to resultant strings:

function join(date, options, separator) {
   function format(option) {
      let formatter = new Intl.DateTimeFormat('en', option);
      return formatter.format(date);
   }
   return options.map(format).join(separator);
}

let options = [{day: 'numeric'}, {month: 'short'}, {year: 'numeric'}];
let joined = join(new Date, options, '-');
console.log(joined);

You can also pull out the parts of a DateTimeFormat one-by-one using DateTimeFormat#format, but note that when using this method, as of March 2020, there is a bug in the ECMAScript implementation when it comes to leading zeros on minutes and seconds (this bug is circumvented by the approach above).

let date = new Date(2010, 7, 5);
let year = new Intl.DateTimeFormat('en', { year: 'numeric' }).format(date);
let month = new Intl.DateTimeFormat('en', { month: 'short' }).format(date);
let day = new Intl.DateTimeFormat('en', { day: '2-digit' }).format(date);
console.log(`{month}-${year}`);

When working with dates and times, it is usually worth using a library (eg. luxon, date-fns, moment.js is not recommended for new projects) because of the many hidden complexities of the field.

Note that the ECMAScript Internationalization API, used in the solutions above is not supported in IE10 (0.03% global browser market share in Feb 2020).

🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date › toString
Date.prototype.toString() - JavaScript | MDN
Date.prototype.toString() returns a string representation of the Date as interpreted in the local timezone, containing both the date and the time — it joins the string representation specified in toDateString() and toTimeString() together, adding a space in between.
🌐
freeCodeCamp
freecodecamp.org › news › how-to-format-dates-in-javascript
How to Format Dates in JavaScript with One Line of Code
November 7, 2024 - By default, when you run new Date() in your terminal, it uses your browser's time zone and displays the date as a full text string, like Fri Jul 02 2021 12:44:45 GMT+0100 (British Summer Time).
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date › toDateString
Date.prototype.toDateString() - JavaScript | MDN
The toDateString() method of Date instances returns a string representing the date portion of this date interpreted in the local timezone.
🌐
Chris Pietschmann
pietschsoft.com › post › 2023 › 09 › 28 › javascript-format-date-to-string
JavaScript: Format Date to String | Chris Pietschmann
September 28, 2023 - JavaScript doesn’t provide a ... can achieve this by following these steps: Create a Date object: First, create a JavaScript Date object representing the date you want to format....
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-program-to-convert-date-to-string
JavaScript Program to Convert Date to String - GeeksforGeeks
July 23, 2025 - The Date.toJSON() method converts a Date object to a string formatted according to the ISO 8601 standard, similar to Date.toISOString(). This method is useful when you need to serialize a Date object to JSON.
🌐
Day.js
day.js.org › docs › en › parse › string-format
String + Format · Day.js
Pass the locale key as the third parameter to parse locale-aware date time string. require('dayjs/locale/es') dayjs('2018 Enero 15', 'YYYY MMMM DD', 'es') You may specify a boolean for the last argument to use strict parsing. Strict parsing requires that the format and input match exactly, including delimiters.
🌐
CSS-Tricks
css-tricks.com › everything-you-need-to-know-about-date-in-javascript
Everything You Need to Know About Date in JavaScript | CSS-Tricks
September 22, 2022 - Plus, timestamps are much more JSON friendly! ... I see. Well my opinion is if you need to handle complicated stuff, going with Date-fns or Moment might still be the best choice. ... The Date​.prototype​.toLocale​String() method actually does a pretty good job constructing human readable dates if you pass in a config.
🌐
Sentry
sentry.io › sentry answers › javascript › how do i format a date in javascript?
How do I Format a Date in JavaScript? | Sentry
The date object has multiple methods for creating a date string in different formats. The two main methods are Date.toLocaleDateString() and Intl.DateTimeFormat(). Both of these are used to return a formatted date string.
🌐
freeCodeCamp
freecodecamp.org › news › how-to-format-a-date-with-javascript-date-formatting-in-js
How to Format a Date with JavaScript – Date Formatting in JS
November 7, 2024 - JavaScript provides a few built-in methods to format dates conveniently. Let's take a look at some of these methods: toDateString(): This method converts the date portion of a Date object into a human-readable string format.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-format-a-date-in-javascript
How to Format a Date in JavaScript? - GeeksforGeeks
July 23, 2025 - In this approach, we will use the different date methods to get the day, date, month and year of the date object and then concat them to form a formatted date string.
🌐
Byby
byby.dev › js-format-date
How to parse and format a date in JavaScript
JavaScript provides several methods for parsing dates, such as Date.parse() and new Date() constructor. It’s important to note that the date string must be in a specific format that can be recognized by the parsing method.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date › toTimeString
Date.prototype.toTimeString() - JavaScript | MDN
The toTimeString() method of Date instances returns a string representing the time portion of this date interpreted in the local timezone.
🌐
Day.js
day.js.org › docs › en › display › format
Format · Day.js
To escape characters, wrap them in square brackets (e.g. [MM]). dayjs().format() // current date in ISO8601, without fraction seconds e.g. '2020-04-02T08:02:17-05:00' dayjs('2019-01-25').format('[YYYYescape] YYYY-MM-DDTHH:mm:ssZ[Z]') // 'YYYYescape 2019-01-25T00:00:00-02:00Z' dayjs('2019-01-25').format('DD/MM/YYYY') // '25/01/2019' More available formats Q Do k kk X x ... in plugin AdvancedFormat · Because preferred formatting differs based on locale, there are a few localized format tokens that can be used based on its locale.
🌐
Tutorial Republic
tutorialrepublic.com › faq › how-to-format-javascript-date-as-yyyy-mm-dd.php
How to Format JavaScript Date as YYYY-MM-DD
// Create a date object from a ...ng("default", { day: "2-digit" }); // Generate yyyy-mm-dd date string var formattedDate = year + "-" + month + "-" + day; console.log(formattedDate); // Prints: 2022-05-04...
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-format-javascript-date-as-yyyy-mm-dd
How To Format JavaScript Date as yyyy-mm-dd? - GeeksforGeeks
June 24, 2025 - Example: In this example, we will use the iso string method to format the JavaScript date as yyyy-mm-dd ... const formatDateISO = (date) => { return date.toLocaleDateString('en-CA'); }; const currentDate = new Date(); console.log(formatDate...