Home > Enterprise >  change date from mm/dd/yy to dd/mm/yy
change date from mm/dd/yy to dd/mm/yy

Time:11-20

enter image description here

I have an interface that contains the card shown in the picture, and as it appears that the card contains a date, but the date is in the form:

'mm/dd/yyyy'

And I want it to be in the form:

'dd/mm/yyyy'

Knowing that I want the content inside the parentheses to remain of type "date", not string or another type.

How do I do that?

        date = {new Date(w.startingDate!)}

CodePudding user response:

You might be able to just do a regex replacement, assuming you have a date string:

var date = "19/11/2022";
var output = date.replace(/^(\d{2})\/(\d{2})/, "$2/$1");
console.log(output);

CodePudding user response:

try this

new Date(w.startingDate).toLocaleString('en-GB').split(',')[0]

console.log(new Date("2022-11-20T00:00:00").toLocaleString('en-GB').split(',')[0])

  • Related