MM/DD/YYYY format

If you have the MM/DD/YYYY format which is default for JavaScript, you can simply pass your string to Date(string) constructor. It will parse it for you.

Copyvar dateString = "10/23/2015"; // Oct 23

var dateObject = new Date(dateString);

document.body.innerHTML = dateObject.toString();
Run code snippetEdit code snippet Hide Results Copy to answer Expand

DD/MM/YYYY format - manually

If you work with this format, then you can split the date in order to get day, month and year separately and then use it in another constructor - Date(year, month, day):

Copyvar dateString = "23/10/2015"; // Oct 23

var dateParts = dateString.split("/");

// month is 0-based, that's why we need dataParts[1] - 1
var dateObject = new Date(+dateParts[2], dateParts[1] - 1, +dateParts[0]); 

document.body.innerHTML = dateObject.toString();
Run code snippetEdit code snippet Hide Results Copy to answer Expand

For more information, you can read article about Date at Mozilla Developer Network.

DD/MM/YYYY - using moment.js library

Alternatively, you can use moment.js library, which is probably the most popular library to parse and operate with date and time in JavaScript:

Copyvar dateString = "23/10/2015"; // Oct 23

var dateMomentObject = moment(dateString, "DD/MM/YYYY"); // 1st argument - string, 2nd argument - format
var dateObject = dateMomentObject.toDate(); // convert moment.js object to Date object

document.body.innerHTML = dateObject.toString();
Copy<script src="https://momentjs.com/downloads/moment.min.js"></script>
Run code snippetEdit code snippet Hide Results Copy to answer Expand

In all three examples dateObject variable contains an object of type Date, which represents a moment in time and can be further converted to any string format.

Answer from Yeldar Kurmangaliyev on Stack Overflow
๐ŸŒ
W3Schools
w3schools.com โ€บ js โ€บ js_date_formats.asp
JavaScript Date Formats
In other words: If a date/time ... central US. Short dates are written with an "MM/DD/YYYY" syntax like this: const d = new Date("03/25/2015"); Try it Yourself ยป...
Top answer
1 of 10
308

MM/DD/YYYY format

If you have the MM/DD/YYYY format which is default for JavaScript, you can simply pass your string to Date(string) constructor. It will parse it for you.

Copyvar dateString = "10/23/2015"; // Oct 23

var dateObject = new Date(dateString);

document.body.innerHTML = dateObject.toString();
Run code snippetEdit code snippet Hide Results Copy to answer Expand

DD/MM/YYYY format - manually

If you work with this format, then you can split the date in order to get day, month and year separately and then use it in another constructor - Date(year, month, day):

Copyvar dateString = "23/10/2015"; // Oct 23

var dateParts = dateString.split("/");

// month is 0-based, that's why we need dataParts[1] - 1
var dateObject = new Date(+dateParts[2], dateParts[1] - 1, +dateParts[0]); 

document.body.innerHTML = dateObject.toString();
Run code snippetEdit code snippet Hide Results Copy to answer Expand

For more information, you can read article about Date at Mozilla Developer Network.

DD/MM/YYYY - using moment.js library

Alternatively, you can use moment.js library, which is probably the most popular library to parse and operate with date and time in JavaScript:

Copyvar dateString = "23/10/2015"; // Oct 23

var dateMomentObject = moment(dateString, "DD/MM/YYYY"); // 1st argument - string, 2nd argument - format
var dateObject = dateMomentObject.toDate(); // convert moment.js object to Date object

document.body.innerHTML = dateObject.toString();
Copy<script src="https://momentjs.com/downloads/moment.min.js"></script>
Run code snippetEdit code snippet Hide Results Copy to answer Expand

In all three examples dateObject variable contains an object of type Date, which represents a moment in time and can be further converted to any string format.

2 of 10
14

Here's one I prepared earlier...

Copy  convertToDate(dateString) {
      //  Convert a "dd/MM/yyyy" string into a Date object
      let d = dateString.split("/");
      let dat = new Date(d[2] + '/' + d[1] + '/' + d[0]);
      return dat;     
  }
๐ŸŒ
MDN Web Docs
developer.mozilla.org โ€บ en-US โ€บ docs โ€บ Web โ€บ JavaScript โ€บ Reference โ€บ Global_Objects โ€บ Date
Date - JavaScript | MDN
The following examples show several ways to create JavaScript dates: Note: Creating a date from a string has a lot of behavior inconsistencies. See date time string format for caveats on using different formats. ... 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 const birthday4 = new Date(1995, 11, 17, 3, 24, 0); const birthday5 = new Date(628021800000); // passing epoch timestamp
๐ŸŒ
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 - const date = new Date(); const formattedDate = date.toLocaleString('en-US', { timeZoneName: 'short' }); console.log(formattedDate); Output: 5/30/2023, 12:00:00 AM PDT. Certain date formatting patterns are commonly used.
๐ŸŒ
Day.js
day.js.org โ€บ docs โ€บ en โ€บ display โ€บ format
Format ยท Day.js
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'
๐ŸŒ
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 - '0' + month : month; // Format the date as dd/mm/yyyy const formattedDate = `${day}/${month}/${year}`; console.log(formattedDate); ... The Intl.DateTimeFormat() constructor is a built-in JavaScript object that enables language-sensitive date ...
๐ŸŒ
Medium
trymysolution.medium.com โ€บ javascript-date-as-in-yyyy-mm-dd-hh-mm-ss-format-or-mm-dd-yyyy-hh-mm-ss-a0c96e8fa888
JavaScript Date as in YYYY-MM-DD hh:mm:ss Format or MM/DD/YYYY hh:mm:ss | by Yogesh D V | Medium
April 11, 2023 - function padTwoDigits(num: number) ... :::: // The function takes a Date object as a parameter and formats the date as YYYY-MM-DD hh:mm:ss....
Find elsewhere
๐ŸŒ
Bobby Hadz
bobbyhadz.com โ€บ blog โ€บ javascript-format-date-dd-mm-yyyy
How to Format a Date as DD/MM/YYYY in JavaScript | bobbyhadz
Copied!const date = new Date(); // โœ… DD/MM/YYYY const result1 = new Date().toLocaleDateString('en-GB'); console.log(result1); // ๐Ÿ‘‰๏ธ 24/07/2023 ... The code can also be tweaked to include the time.
๐ŸŒ
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 - // Test with 100,000 operations const COUNT = 100000; // Native JS console.time('Native'); for (let i = 0; i < COUNT; i++) { new Date().toISOString(); } console.timeEnd('Native'); // Typically fastest // date-fns console.time('date-fns'); for (let i = 0; i < COUNT; i++) { format(new Date(), 'yyyy-MM-dd\'T\'HH:mm:ss.SSS\'Z\''); } console.timeEnd('date-fns'); // Close second // Day.js console.time('Day.js'); for (let i = 0; i < COUNT; i++) { dayjs().format('YYYY-MM-DDTHH:mm:ss.SSS[Z]'); } console.timeEnd('Day.js'); // Usually faster than Moment // Moment.js console.time('Moment'); for (let i = 0
๐ŸŒ
Futurestud.io
futurestud.io โ€บ tutorials โ€บ how-to-format-a-date-yyyy-mm-dd-in-javascript-or-node-js
How to Format a Date YYYY-MM-DD in JavaScript or Node.js
format(new Date()) // '2022-11-17' format(new Date('2022-5-4')) // '2022-05-04' format() format(1234) // ๐Ÿ’ฅ Error "Invalid argument.
๐ŸŒ
Byby
byby.dev โ€บ js-format-date
How to parse and format a date in JavaScript
It does not provide full control over the formatting of the date string, as it relies on the formatting rules and conventions defined by the locale. const date = new Date(); // British English uses day-month-year order console.log(date.toLocaleDateString('en-GB')); // 24/04/2023 // US English ...
๐ŸŒ
W3Resource
w3resource.com โ€บ javascript-exercises โ€บ javascript-basic-exercise-3.php
JavaScript: Display the current date in various format - w3resource
let today = new Date(); let dd = today.getDate(); let mm = today.getMonth()+1; const yyyy = today.getFullYear(); if(dd<10) { dd=`0${dd}`; } if(mm<10) { mm=`0${mm}`; } today = `${mm}-${dd}-${yyyy}`; console.log(today); today = `${mm}/${dd}/${yyyy}`; ...
๐ŸŒ
Mastering JS
masteringjs.io โ€บ tutorials โ€บ fundamentals โ€บ date-tostring-format-yyyy-mm-dd
Format a JavaScript Date to YYYY MM DD - Mastering JS
const date = new Date(); const year = date.getFullYear() * 1e4; // 1e4 gives us the the other digits to be filled later, so 20210000. const month = (date.getMonth() + 1) * 100; // months are numbered 0-11 in JavaScript, * 100 to move two digits ...
๐ŸŒ
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 - Use toISOString().split('T')[0] to format any date as YYYY-MM-DD. const formatted = new Date().toISOString().split('T')[0]
๐ŸŒ
Squash
squash.io โ€บ how-to-format-javascript-date-as-yyyy-mm-dd
How to Format JavaScript Dates as YYYY-MM-DD
Here are two possible approaches: The toISOString() method returns a string representing the date in the ISO format (YYYY-MM-DDTHH:mm:ss.sssZ). By manipulating this string, we can extract the YYYY MM DD format. const date = new Date(); const ...
๐ŸŒ
TutorialsTeacher
tutorialsteacher.com โ€บ javascript โ€บ javascript-date
JavaScript Date: Create, Convert, Compare Dates in JavaScript
The following example converts a date string to DD-MM-YYYY format. Example: Get Date Segments Copy ยท var date = new Date('4-1-2015'); // M-D-YYYY var d = date.getDate(); var m = date.getMonth() + 1; var y = date.getFullYear(); var dateString = (d &lt;= 9 ? '0' + d : d) + '-' + (m <= 9 ? '0' + m : m) + '-' + y; Try it ยท Use third party JavaScript Date library like datejs.com or momentjs.com to work with Dates extensively in JavaScript.
๐ŸŒ
Tutorial Republic
tutorialrepublic.com โ€บ faq โ€บ how-to-format-javascript-date-as-yyyy-mm-dd.php
How to Format JavaScript Date as YYYY-MM-DD
You can simply use the toLocaleString() method to format a JavaScript date as yyyy-mm-dd. Let's take a look at the following example to understand how it basically works: ... // Create a date object from a date string var date = new Date("Wed, ...