我使用的是React-Native.有没有办法在Moment.js中获取最近28天的数据?我看到一个插件 moment-range
但我不想安装它。
基本上我需要的是过去28天的数组。
举个例子。
const now = moment()
const lastMonth = moment.subtract(28, 'days')
const lastMonthArr = [1,2....28]
你可以试试这样的东西。
let now = moment();
let pastDates = [];
for( let i=1;i<=28;i++) {
now = now.subtract(1, 'day')
console.log(now.format('MMM Do YY'))
pastDates.push(now)
}