How can i format a date in javascript?
let date = '2022-01-01';
let fd = date.toLocaleString("nl-NL"); // in dutch format
alert(fd); // outputs also 2022-01-01; should be 01-01-2022
How can i format a date in javascript?
let date = '2022-01-01';
let fd = date.toLocaleString("nl-NL"); // in dutch format
alert(fd); // outputs also 2022-01-01; should be 01-01-2022
You are not constructing a Date() object.
const date = new Date('2022-01-01')
let fd = date.toLocaleString("nl-NL");
//or make it by yourself
//let fd = date.getDate() + '-' + (date.getMonth() + 1) + '-' + date.getFullYear()
console.log(fd);
let date = '2022-01-01';
var options = {year: "numeric", month: "numeric", day: "numeric"};
fd = (new Intl.DateTimeFormat("en-AU", options).format(new Date(date))).replace(/\//g, '-');
alert(fd);
try this.