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
There are many ways to format a date as a string. The JavaScript specification only specifies one format to be universally supported: the date time string format, a simplification of the ISO 8601 calendar date extended format.
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).

Discussions

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
Convert date in JavaScript to yyyy-mm-dd format
What is the best way to transform it into the format 2014-05-11 using JavaScript? function formatDate(inputDate) { const dateObj = new Date(inputDate); const year = dateObj.getFullYear(); const month = String(dateObj.getMonth() + 1).padStart(2, '0'); const day = String(dateObj.getDate()).p... More on community.latenode.com
🌐 community.latenode.com
0
December 3, 2024
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
javascript - Format Date as "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" - Stack Overflow
I need to format a date as yyyy-MM-dd'T'HH:mm:ss.SSS'Z' as specified by Parse's REST API for Facebook. I was wondering what the most lightweight solution to this would be. More on stackoverflow.com
🌐 stackoverflow.com
🌐
W3Schools
w3schools.com › js › js_date_formats.asp
JavaScript Date Formats
The ISO 8601 syntax (YYYY-MM-DD) is also the preferred JavaScript date format:
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Intl › DateTimeFormat
Intl.DateTimeFormat - JavaScript | MDN
The initial value of the [Symbol.toStringTag] property is the string "Intl.DateTimeFormat". This property is used in Object.prototype.toString(). ... Getter function that formats a date according to the locale and formatting options of this DateTimeFormat object.
🌐
Codecademy
codecademy.com › article › javascript-date-format
How to Format a Date in JavaScript | Codecademy
To get a Date object for a specific date, we can pass the date as a string to the Date() constructor. ... You can pass the input date string to the Date() constructor in other formats as well, such as January 14, 2025 or 2025-01-14.
🌐
Medium
habtesoft.medium.com › 8-ways-of-date-formatting-in-javascript-1380625a1f50
8 Ways of Date Formatting in Javascript | by habtesoft | Medium
October 18, 2024 - const date = new Date(); // Default locale (browser's locale) console.log(date.toLocaleDateString()); // e.g., "9/20/2024" // Custom locale console.log(date.toLocaleDateString('en-GB')); // "20/09/2024" (dd/mm/yyyy) console.log(date.toLocal...
Find elsewhere
🌐
Bugfender
bugfender.com › blog › javascript-date-and-time
The Definitive Guide to JavaScript Date and Time | Bugfender
February 18, 2025 - Understand JavaScript Date object basic operations. Learn multiple ways to create, format, and manipulate Date objects.
🌐
Reddit
reddit.com › r/javascript › why doesn't javascript have a native date() formatting method?
r/javascript on Reddit: Why doesn't JavaScript have a native Date() formatting method?
March 24, 2014 -

Here's how you'd output today's time and date (10:30:14 03/21/2014, at the moment). Please correct any mistakes, as I'm not a PHP, JAVA, C# or PERL developer.


PHP

$today = date("h:i:s m/d/y");

JAVA

String today = new SimpleDateFormat("hh:mm:ss MM/dd/yyyy").format(date);

C#

DateTime date = new DateTime();
String today = date.ToString("H:mm:ss MM/dd/yyyy");

PERL

my $today = strftime "%H:%M:%S %m/%d/%Y", localtime;

JavaScript

var d = new Date(),
    month = d.getMonth() + 1,
    day = (d.getDate() < 10) ? "0" + d.getDate() : d.getDate(),
    year = d.getFullYear(),
    hours = d.getHours(),
    minutes = d.getMinutes(),
    seconds = (d.getSeconds() < 10) ? "0" + d.getSeconds() : d.getSeconds();

if (hours > 12) {
    hours -= 12;
} else if (hours === 0) {
    hours = 12;
}

var today = hours + ":" + minutes + ":" + seconds + " " + month + "/" + day + "/" + year;

WTF JavaScript? Y u so complicated???

Why can't we have something like .format() or .toString():

var today = new Date().format("h:i:s m/d/y")

EDIT: Thanks for the answers everyone. It helped a lot.

I should've clarified originally that I was looking to find out WHY it's not native to the language, as opposed to HOW to do it via a 3rd party library (I'm aware of momentjs and it's great).

Anyway, the top 2 answers are great - exactly what I was looking for. Thank you.

I was unaware of Intl.DateTimeFormat (thanks u/SpsD3GoiFSmXBAl), which helps:

var date = new Date(),
    today = new Intl.DateTimeFormat().format(date); // 3/24/2014 (also allows for customization options)
Top answer
1 of 5
13
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.
2 of 5
8
First: npm install strftime then: var strftime = require('strftime'); console.log(strftime("%H:%M:%S %m/%d/%Y")); although this format is kind of terrible and not international. It's much better to defer to ISO8601 on that, which is simple to use with strftime: var strftime = require('strftime'); console.log(strftime("%F %T")); in node you can just node time.js and for the browser there's browserify . strftime has a small payload footprint: $ browserify -r strftime | wc -c 10401 $ browserify -r strftime | uglifyjs -cm | gzip | wc -c 1775 It's a good idea to embrace a module system and package manager sooner rather than later because you can leverage all the great work that's been done in userland outside of the core language.
🌐
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 - While Moment.js was once the go-to library for date handling in JavaScript, it is now considered legacy. The Moment.js team has officially declared the library in maintenance mode and recommends newer alternatives. That said, many existing projects still use it, so it’s worth understanding its approach. ... Let’s look at a typical Moment.js workflow: creating date objects from strings or custom formats, formatting them into readable outputs, adjusting dates by adding or subtracting time, and converting them to specific time zones.
🌐
Latenode
community.latenode.com › other questions › javascript
Convert date in JavaScript to yyyy-mm-dd format - JavaScript - Latenode Official Community
December 3, 2024 - I possess a date string in the form Sun May 11, 2014. What is the best way to transform it into the format 2014-05-11 using JavaScript? function formatDate(inputDate) { const dateObj = new Date(inputDate); const year = dateObj.getFullYear(); const month = String(dateObj.getMonth() + 1).padStart(2, '0'); const day = String(dateObj.getDate()).padStart(2, '0'); return `${year}-${month}-${day}`; } const date = 'Sun May 11, 2014'; console.log(formatDate(date)); The code snippet...
🌐
Day.js
day.js.org › docs › en › display › format
Format · Day.js
dayjs().format() // current date in ISO8601, without fraction seconds e.g.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date › toLocaleDateString
Date.prototype.toLocaleDateString() - JavaScript | MDN
October 30, 2025 - When the method is called many times with the same arguments, it is better to create an Intl.DateTimeFormat object and use its format() method, because a DateTimeFormat object remembers the arguments passed to it and may decide to cache a slice of the database, so future format calls can search ...
🌐
freeCodeCamp
freecodecamp.org › news › javascript-date-format-how-to-format-a-date-in-js
JavaScript Date Format – How to Format a Date in JS
November 7, 2024 - Moment.js is a JavaScript date and time library that you can use to quickly format your dates without handling the logic with so many lines of code.
🌐
date-fns
date-fns.org
date-fns - modern JavaScript date utility library
date-fns provides the most comprehensive yet simple and consistent toolset for manipulating JavaScript dates in a browser & Node.js.
🌐
CoreUI
coreui.io › answers › how-to-format-date-as-yyyy-mm-dd-in-javascript
How to format date as YYYY-MM-DD in JavaScript · CoreUI
September 30, 2025 - The most reliable and widely compatible approach is using toISOString() with string splitting to extract the date portion. This method ensures consistent ISO 8601 formatting regardless of timezone complexities.
🌐
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

🌐
W3Schools
w3schools.com › js › js_dates.asp
JavaScript Dates
February 4, 2026 - JavaScript will (by default) output dates using the toString() method. This is a string representation of the date, including the time zone. The format is specified in the ECMAScript specification:
🌐
Tabnine
tabnine.com › home › how to format date in javascript
How to Format Date in JavaScript - Tabnine
July 25, 2024 - We’ll touch on those third-party solutions in a moment, but let’s get started with some basic JavaScript time formatting. JavaScript’s Date() function object contains a long list of methods that can be used to manipulate the date outcome, as well as display time and date data as specific instances or ranges of time, dates, and time zones.