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 - function formatDate(date, format) { const day = String(date.getDate()).padStart(2, '0'); const month = String(date.getMonth() + 1).padStart(2, '0'); const year = date.getFullYear(); const hours = String(date.getHours()).padStart(2, '0'); const minutes = String(date.getMinutes()).padStart(2, '0'); const seconds = String(date.getSeconds()).padStart(2, '0'); // Replace tokens with actual values return format .replace('YYYY', year) .replace('MM', month) .replace('DD', day) .replace('HH', hours) .replace('mm', minutes) .replace('ss', seconds); } const date = new Date('2025-02-18T14:30:45Z'); console.log(formatDate(date, 'YYYY-MM-DD')); // "2025-02-18" console.log(formatDate(date, 'DD/MM/YYYY HH:mm:ss')); // "18/02/2025 14:30:45"
🌐
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}`; ...
🌐
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 ...
🌐
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]
🌐
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.