Skip to content

JS 使用 moment 获取时间区间

js
// 前1天
console.log(moment().day(moment().day() - 1).startOf('day').unix());


//上周第一天
console.log(moment().week(moment().week() - 1).startOf('week').unix());
//上周最后一天
console.log(moment().week(moment().week() - 1).endOf('week').unix());

//本周第一天
console.log(moment().week(moment().week()).startOf('week').unix());
//本周最后一天
console.log(moment().week(moment().week()).endOf('week').unix());

//下周第一天
console.log(moment().week(moment().week() + 1).startOf('week').unix());
//下周最后一天
console.log(moment().week(moment().week() + 1).endOf('week').unix());

//上个月第一天
console.log(moment().month(moment().month() - 1).startOf('month').unix());
//上个月最后一天
console.log(moment().month(moment().month() - 1).endOf('month').unix());

//本月第一天
console.log(moment().month(moment().month()).startOf('month').unix());
//本月最后一天
console.log(moment().month(moment().month()).endOf('month').unix());

//下个月第一天
console.log(moment().month(moment().month() + 1).startOf('month').unix());
//下个月最后一天
console.log(moment().month(moment().month() + 1).endOf('month').unix());