原生js寫法
function getFormatDate() { let now = new Date(); function pad(number) { if (number < 10) { return “0” + number; } return number; } return ( now。getFullYear() + “-” + pad(now。getMonth() + 1) + “-” + pad(now。getDate()) );}console。log(getFormatDate());
使用moment庫
使用dayjs庫(庫小好用)