Skip to content
Advertisement

how to format a date from an existing dateformat

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

Advertisement

Answer

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); 
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement