如何在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
uj5u.com熱心網友回復:
您沒有構建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);
uj5u.com熱心網友回復:
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);
試試這個。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/407499.html
標籤:
