// 获取指定时间戳所在一周的时间
function formatDate(date){const year = date.getFullYear()
let month = date.getMonth()+1
let day = date.getDate()if(month <10){
month = `0${month}`
}if(day <10){
day = `0${day}`
}return `${year}-${month}-${day}`
}
function getMonthdays(timestamp){
let MonthDate =newDate(timestamp)const year = MonthDate.getFullYear()const month =
MonthDate.getMonth()+1<10? `0${MonthDate.getMonth()+1}`
: MonthDate.getMonth()+1
let dayArr =[]
let eddDate =newDate(year, MonthDate.getMonth()+1,0).getDate()
let starStamp =newDate(`${year}-${month}-01`).getTime()
console.log(starStamp, month)for(let i =0; i < eddDate; i++){
let val =Number(starStamp)+ i *86400000
console.log(val)
dayArr.push(formatDate(newDate(val)))}
console.log(dayArr, eddDate)}
//获取指定时间戳所在月整月的时间
function getMonthdays(timestamp){
let MonthDate =newDate(timestamp)const year = MonthDate.getFullYear()const month =
MonthDate.getMonth()+1<10? `0${MonthDate.getMonth()+1}`
: MonthDate.getMonth()+1
let dayArr =[]
let eddDate =newDate(year, MonthDate.getMonth()+1,0).getDate()for(let i =1; i <= eddDate; i++){
dayArr.push(`${year}-${month}-${i<10?`0${i}`:i}`)}
console.log(dayArr, eddDate)}
// 获取指定时间戳 当前 前 后 正月的时间
function getMonthdays(timestamp){
let MonthDate =newDate(timestamp)const year = MonthDate.getFullYear()const month =
MonthDate.getMonth()+1<10? `0${MonthDate.getMonth()+1}`
: MonthDate.getMonth()+1
let dayArr =[]
let eddDate =newDate(year, MonthDate.getMonth()+1,0).getDate()for(let i =1; i <= eddDate; i++){
dayArr.push(`${year}-${month}-${i <10? `0${i}` : i}`)}return dayArr
}
function getmonths(timestamp){
let MonthDate =newDate(timestamp)const year = MonthDate.getFullYear()const month = MonthDate.getMonth()+1
let monthNum =newDate(year, month,0)
let starstamp =newDate(`${year}/${month}/1`).getTime()
var timeEnd = Date.parse(monthNum)
let boeforeMonthday = starstamp -86400000
let afterMonthday = timeEnd +86400000const arr =[boeforeMonthday, timeEnd, afterMonthday]
let endVal ={}for(let i =0; i <= arr.length -1; i++){
endVal[i]=getMonthdays(arr[i])} console.log(endVal)}