js获取当月的第一天和当月的最后一天

//获取当月的第一天
var date = new Date();
date.setMonth(date.getMonth(), 1);//将日期设置为本月的第一天
console.log("当月的第一天:" + date);
//获取当月的最后一天
var date = new Date();
date.setMonth(date.getMonth()+1, 0);//将日期设置为下个月的第零天(也就是本月的最后一天)
console.log("当月的最后一天:" + date);

 

posted @ 2024-03-13 14:22  一隅桥畔  阅读(148)  评论(0编辑  收藏  举报