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
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date
Date - JavaScript | MDN
... const today = new Date(); const birthday = new Date("December 17, 1995 03:24:00"); // DISCOURAGED: may not work in all runtimes const birthday2 = new Date("1995-12-17T03:24:00"); // This is standardized and will work reliably const birthday3 = new Date(1995, 11, 17); // the month is 0-indexed ...
🌐
W3Schools
w3schools.com › js › js_date_formats.asp
JavaScript Date Formats
const d = new Date("2015-03-25T12:00:00-06:30"); Try it Yourself » · UTC (Universal Time Coordinated) is the same as GMT (Greenwich Mean Time). Omitting T or Z in a date-time string can give different results in different browsers. When setting a date, without specifying the time zone, JavaScript will use the browser's time zone.
Discussions

How get a date formatted like 2023-02-07 in JS?
You can do a quick and dirty format to yyyy-mm-dd with date.toISOString().slice(0, 10) More on reddit.com
🌐 r/webdev
26
0
March 13, 2023
Why doesn't JavaScript have a native Date() formatting method?
As to why JS has such a bad standard lib, I personally think it has multiple causes that all worked together to keep the JS language static for a really long time. First off, Brendan Eich created the language in a very short period of time. Designing/delivering a rich API/lib simply wasn't possible. At the time, JS was meant as a counterpoint to Java (and their applets). You weren't meant to write anythig big in JS (that's also why it's execution model is so primitive), since you had Java for big stuff and java's got a huge std lib. Given the nature of the web, and the fact that JS isn't owned by a single entity makes any changes difficult. Microsoft's lack of interest in the mid early 00s for example did little to help, as well as a flurry of mixed directions JS took in that time period (class based OO for example). If you're still stuck developing for desktop browsers (and especially IE) you're essentially writing in the same language as existed 15 years ago, which is insane given how much the rest of the development experience has advanced. What JS needs most of all is IMO a good module definition. Nothing can really move beyond the basics until we at least get some hard abstractions we can depend on from the language itself. More on reddit.com
🌐 r/javascript
41
20
March 24, 2014
Why you shouldn't use Moment.js...
We use moment a lot in our codebase, and if it wasn't around I don't know how much other bugs we probably would have had if we had to implement our own date handling code at the time. And I mean, the fact that the momentjs people are developing a modern competitor to momentjs (luxon) probably means that they agree that moment isn't the greatest option around nowadays. I hope we're not collectively going to start to shit on moment just because it isn't the best option anymore, like we are doing with jQuery. More on reddit.com
🌐 r/javascript
147
225
March 10, 2019
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 › Date
Date() constructor - JavaScript | MDN
// reduced time precision with `privacy.resistFingerprinting` enabled new Date().getTime(); // Might be: // 1519129853500 // 1519129858900 // 1519129864400 // … · The following examples show several ways to create JavaScript dates:
🌐
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 couple ways ... manipulation. ... const date = new Date(); const formattedDate = `${date.getDate()}-${date.getMonth() + 1}-${date.getFullYear()}`; console.log(formattedDate);...
🌐
Codecademy
codecademy.com › article › javascript-date-format
How to Format a Date in JavaScript | Codecademy
The Date() constructor returns the formatted date in the same format as new Date(), but in a string: "Wed Feb 12 2025 11:47:21 GMT+0530 (India Standard Time)" ... The default format does the job in many cases.
🌐
Reddit
reddit.com › r/webdev › how get a date formatted like 2023-02-07 in js?
r/webdev on Reddit: How get a date formatted like 2023-02-07 in JS?
March 13, 2023 -

I'm going insane. I had this feature working perfectly. Took 2 weeks vacation. I come back and it's broken.

I know y'all will say this is impossible, but I was getting that format by using `date.toLocaleDateString('en-CA')`. I know the spec says that format is "dd/MM/yyyy", which isn't what I want, but I was giving me the format in the title, I swear to God.

This is such a stupid little thing but I've already spent hours on SO. It's just endless threads about people confused about datetimes and the differences between timezones and offsets and no one's talking about this silly little thing.

I have my new date: Wed Feb 08 2023 00:00:00 GMT-0500 (Eastern Standard Time)

I just need a simple operation to flip the string around so it becomes 2023-03-08

That is it. Please help

p.s. the date is always set to midnight user local time so offset can be ignored. Whatever day they're experiencing is the day to be formatted. Thank you

Find elsewhere
🌐
Bugfender
bugfender.com › blog › javascript-date-and-time
The Definitive Guide to JavaScript Date and Time | Bugfender
February 18, 2025 - When you do not specify a locale, the Intl.DateTimeFormat uses the default locale. const date = new Date(Date.UTC(2023, 09, 17, 13, 1, 0)); // Format the date with the default locale, and the default time zone console.log(new Intl.DateTimeF...
🌐
LogRocket
blog.logrocket.com › home › how to format dates in javascript: methods, libraries, and best practices
How to format dates in JavaScript: Methods, libraries, and best practices - LogRocket Blog
May 8, 2025 - // Creating a new Date object const now = new Date(); // Current date and time const isoDate = new Date('2025-02-18T14:30:00.000Z'); // From date string const withComponents = new Date(2025, 1, 18); // Year, month (0-indexed!), day const ...
🌐
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...
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Intl › DateTimeFormat
Intl.DateTimeFormat - JavaScript | MDN
The date and time formats can be customized using the options argument: ... const date = new Date(Date.UTC(2012, 11, 20, 3, 0, 0, 200)); // request a weekday along with a long date let options = { weekday: "long", year: "numeric", month: "long", day: "numeric", }; console.log(new Intl.DateTimeFormat("de-DE", options).format(date)); // "Donnerstag, 20.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-get-current-formatted-date-dd-mm-yyyy-in-javascript
How to Get Current Formatted Date dd/mm/yyyy in JavaScript? - GeeksforGeeks
July 11, 2025 - JavaScript · const today = new Date(); const formattedDate = new Intl.DateTimeFormat('en-GB', { day: '2-digit', month: '2-digit', year: 'numeric' }).format(today); console.log(formattedDate); Output ·
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date › parse
Date.parse() - JavaScript | MDN
// Standard date-time string format const unixTimeZero = Date.parse("1970-01-01T00:00:00Z"); // Non-standard format resembling toUTCString() const javaScriptRelease = Date.parse("04 Dec 1995 00:12:00 GMT"); console.log(unixTimeZero); // Expected output: 0 console.log(javaScriptRelease); // Expected output: 818035920000
🌐
Day.js
day.js.org › docs › en › display › format
Format · Day.js
dayjs().format() // current date in ISO8601, without fraction seconds e.g.
🌐
JavaScript.info
javascript.info › tutorial › the javascript language › data types
Date and time
Otherwise, the full date in the format "DD.MM.YY HH:mm". That is: "day.month.year hours:minutes", all in 2-digit format, e.g. 31.12.16 10:00. ... alert( formatDate(new Date(new Date - 1)) ); // "right now" alert( formatDate(new Date(new Date ...
🌐
W3Resource
w3resource.com › javascript-exercises › javascript-basic-exercise-3.php
JavaScript: Display the current date in various format - w3resource
This JavaScript program retrieves the current date and formats it in multiple ways (mm-dd-yyyy, mm/dd/yyyy, dd-mm-yyyy, dd/mm/yyyy). It uses the Date object to get the current day, month, and year, and then adds leading zeros if necessary to ...
🌐
DEV Community
dev.to › iamcymentho › formatting-dates-in-javascript-a-comprehensive-guide-1i9o
Formatting Dates in JavaScript: A Comprehensive Guide - DEV Community
December 17, 2024 - LinkedIn Account : LinkedIn Twitter Account: Twitter Credit: Graphics sourced from JFormatting Dates in JavaScript: A Comprehensive Guide ... The 0-indexed months are a real gotcha in JavaScript. Christmas is new Date(2023, 11, 25), not new Date(2023, 12, 25).
🌐
W3Schools
w3schools.com › js › js_dates.asp
JavaScript Dates
February 4, 2026 - new Date() creates a date object with the current date and time: ... Date string formats are described in the next chapter.
🌐
Medium
medium.com › @daboigbae › how-to-format-date-in-javascript-a-comprehensive-guide-7e0b981904a
How to Format Date in JavaScript: A Comprehensive Guide 📅💻 | by daboigbae | Medium
August 7, 2023 - Learn how to format dates in JavaScript with ease. This guide covers everything from basic methods to custom formatting.
🌐
Vultr Docs
docs.vultr.com › javascript › examples › format-the-date
JavaScript Program to Format the Date | Vultr Docs
December 19, 2024 - const now = new Date(); const timeZone = 'Asia/Tokyo'; const timeZoneOptions = { timeZoneName: 'long' }; console.log(now.toLocaleString('en-US', { ...timeZoneOptions, timeZone })); Explain Code · In this example, the date and time are displayed along with the full name of the time zone, demonstrating how to manipulate time zone data in date formatting. JavaScript provides various methods to format and manipulate dates, adaptable to almost any development scenario.