以下是使用JavaScript获取本月第一天和最后一天的日期的代码:

// 获取当前日期
const currentDate = new Date();

// 获取本月第一天
const firstDay = new Date(currentDate.getFullYear(), currentDate.getMonth(), 1);

// 获取本月最后一天
const lastDay = new Date(currentDate.getFullYear(), currentDate.getMonth() + 1, 0);

// 将日期转换为字符串格式
const firstDayStr = firstDay.toISOString().substr(0, 10);
const lastDayStr = lastDay.toISOString().substr(0, 10);

console.log("本月第一天:" + firstDayStr);
console.log("本月最后一天:" + lastDayStr);

运行以上代码,将会输出本月的第一天和最后一天的日期。

用js获取本月的第一天和最后一天的日期

原文地址: https://www.cveoy.top/t/topic/buTm 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录