moment 时间相关

//获取前一个月

const lastMonthToday = new Date(

Math.round(new Date().getTime()/1000)*1000 - 30 * 24 * 60 * 60 * 1000

);

const lastMonthYear = lastMonthToday.getFullYear();

const lastMonth = lastMonthToday.getMonth() + 1;

//获取某时间点所在的一个月的时间戳范围

const getAllMonthTimestr = (date:moment) => {

let time = new Date(date);//当前月 要计算其他时间点自己传入即可

let year = time.getFullYear();

let month = parseInt(time.getMonth() + 1);

//开始时间 时间戳

let start = new Date( year + "-" + month + "-01 00:00:00" ).getTime()

//结束时间 时间戳

if( month === 12 ){

month = 0;

year += 1;

}

let end = new Date( year + "-" + ( month + 1 ) + "-01 00:00:00" ).getTime();

return [start,end];

}

猜你喜欢

转载自blog.csdn.net/weixin_41606276/article/details/112954912