[Solved] Format date with “/” to “-” with javascript [duplicate]


.toLocaleDateString() returns a string formatted according to the user’s locale, meaning the format will match whatever is set on the user’s machine. For me, that’s 06/01/2016 but for an American it might be 01/06/2016 (because they’re weird like that).

You should define your own format if you want a fixed one:

function pad(n) {return (n<10 ? "0" : "")+n;}
return pad(_date.getDate()) + "-" + pad(_date.getMonth()+1) + "-" + _date.getFullYear();

0

solved Format date with “/” to “-” with javascript [duplicate]