小程序获取日期 年月日

发布时间 2023-09-14 08:05:11作者: 西北逍遥

在小程序中,可以使用Date对象来获取当前的年、月和日

 

const now = new Date();

const year = now.getFullYear(); // 获取当前年份
const month = now.getMonth() + 1; // 获取当前月份,注意月份是从0开始的,因此需要加1
const day = now.getDate(); // 获取当前日期

console.log(`当前年份:${year}`);
console.log(`当前月份:${month}`);
console.log(`当前日期:${day}`);

 

 

 

 

###############################