1

When converting date for example:

var dateObj = new Date("10/01/2019");
console.log(dateObj);

returns Tue Oct 01 2019 00:00:00 i.e. it takes in the day as month and likewise with the month value

How to make new Date() to take dd/mm/yyyy ??

akg1421
  • 51
  • 12
  • @User863 Yes I have actually posted a duplicate question. sorry! Maybe users can get directed from here to original post...so should i let my question stay or **delete** it? – akg1421 Oct 04 '19 at 11:03
  • 1
    It's OK to leave your question here. The same basic question can present itself in many different ways resulting in different subjects even if the answer is the same. I've added another duplicate as it has more information on why the built–in parser behaves the way it does (and why you should avoid using it). – RobG Oct 04 '19 at 22:23

1 Answers1

0

Answer is here: https://stackoverflow.com/a/33299764/6664779

(From original answer) We can use split function and then join up the parts to create a new date object:

var dateString = "23/10/2019"; // 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();
akg1421
  • 51
  • 12