js获取月初月末
程序员文章站
2022-03-03 09:06:29
...
<script>
var time = new Date();
var timeYear = time.getFullYear();
var timeMonth = time.getMonth()+1;
if(timeMonth>12){
timeMonth = 1;
y++
}
var monthLastDay = new Date(timeYear,timeMonth,0).getDate(); //当前月月末日
var yc = timeYear+"-"+(timeMonth<10?"0"+timeMonth:timeMonth)+"-"+"01"+" 00:00:00";
var ym = timeYear+"-"+(timeMonth<10?"0"+timeMonth:timeMonth)+"-"+(monthLastDay<10?"0"+monthLastDay:monthLastDay)+" 23:59:59";
console.log("月初=>",yc)
console.log("月末=>",ym)
</script>
推荐阅读