下面是总结的一些使用moment.js某些时间段的方法:
今天:moment(), moment()
昨天:moment().subtract(1, ‘days’), moment().subtract(1, ‘days’)
最近7天:moment().subtract(6, ‘days’), moment()
最近30天:moment().subtract(29,‘days’), moment()
当周:moment().startOf(‘week’), moment().endOf(‘week’)
当月:moment().startOf(‘month’), moment().endOf(‘month’)
本年:moment().startOf(‘year’), moment().endOf(‘year’)
上周:moment().week(moment().week()-1).startOf(‘week’), moment().week(moment().week()-1).endOf(‘week’)
上月:moment().month(moment().month()-1).startOf(‘month’), moment().month(moment().month()-1).endOf(‘month’)
去年:moment().year(moment().year()-1).startOf(‘year’), moment().year(moment().year()-1).endOf(‘year’)
上个季度:moment().quarter(moment().quarter() - 1).startOf(‘quarter’), moment().quarter(moment().quarter() - 1).endOf(‘quarter’)