如何从现有日期格式格式化日期

how to format a date from an existing dateformat

如何在 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

您没有构建 Date() 对象。

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); 

试试这个。