js获取当前月第一天和下个月第一天
作者:互联网
let date = new Date()
let month = parseInt(date.getMonth() + 1)
let year = date.getFullYear()
let star_time = ''
let end_time = ''
let next_month = ''
let cur_month = month < 10 ? '0' + month : month
star_time = year + '-' + cur_month + '-01'
if (date.getMonth() == 11) {
end_time = Number(year) + 1 + '-01' + '-01'
} else {
next_month = parseInt(date.getMonth() + 2) < 10 ? '0' + parseInt(date.getMonth() + 2) : parseInt(date.getMonth() + 2)
end_time = year + '-' + next_month + '-01'
}
console.log(star_time)
console.log(end_time)
标签:第一天,下个月,year,month,let,time,date,js,getMonth 来源: https://blog.csdn.net/weixin_39983904/article/details/120176687