我正在使用React-Native。在Moment.js中有没有办法获得从现在开始的最后28天?我看到了一个插件moment-range,但我不想安装它。
基本上,我需要的是过去28天的数组。
示例:
const now = moment()
const lastMonth = moment.subtract(28, 'days')
const lastMonthArr = [1,2....28]发布于 2020-05-19 21:14:38
您可以尝试如下所示:
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)
}https://stackoverflow.com/questions/61891437
复制相似问题