const getDay = (num) => {
return num<10?'0'+num:num
}
const currentDate = new Date();
const year = currentDate.getFullYear();
const month = currentDate.getMonth() + 1; // 月份从0开始,所以需要加1
const day = currentDate.getDate();
const hours = currentDate.getHours();
const minutes = currentDate.getMinutes();
const seconds = currentDate.getSeconds();
console.log(`${year}-${getDay(month)}-${getDay(day)}`) //2024-06-14
获取当前时间年月日,选择时间、倒计时等程序都用得到的代码。