// 创建一个当前日期对象
const today = new Date();

// 获取本年
const year = today.getFullYear();

// 获取本月(注意:getMonth() 返回的值从 0 开始,需要 +1)
const month = today.getMonth() + 1;

// 获取本日
const day = today.getDate();

// 获取本月(补全两位数)

const month2 = (today.getMonth() + 1).toString().padStart(2, ‘0’);

// 获取本日(补全两位数)

const day2 = today.getDate().toString().padStart(2, ‘0’);

console.log(“本年:”, year);
console.log(“本月:”, month);
console.log(“本日:”, day);

console.log(“月:”, month2 );
console.log(“日:”, day2);

/*

本年: 2024

本月: 2

本日: 7

月: 02

日: 07

*/

作者 admin

百度广告效果展示