// 获取当前的年月日并打印
function getYearMonthDay() {
const now = new Date(); // 创建一个表示当前日期和时间的Date对象
const year = now.getFullYear(); // 获取当前年份
const month = now.getMonth() + 1; // 获取当前月份(注意:getMonth()返回的是0-11,所以需要加1)
const day = now.getDate(); // 获取当前日期
// 返回格式化的年月日字符串
return `${year}-${String(month).padStart(2, '0')}-${String(day).padStart(2, '0')}`;
}
console.log(getYearMonthDay()); // 输出类似 "2023-10-05"
上一篇:js date 年月日
下一篇:js 获取当月第一天
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站