如何在 JavaScript 中获取年月日
获取当前年月日:
使用 Date 对象的 getFullYear(), getMonth() 和 getDate() 方法。
const now = new Date(); const year = now.getFullYear(); const month = now.getMonth() + 1; // 月份从 0 开始,因此需要加 1 const day = now.getDate(); console.log(`${year}-${month}-${day}`);