momentjs - Moment.js 获取最近 28 天
问题描述
我正在使用 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)
}
推荐阅读
- python - 在 pandas 的下游作业中通过 Athena 读取分区数据
- google-cloud-platform - 从触发器开始数据准备作业后运行 SQL 更新语句 - Google Cloud
- android-jetpack-compose - 如何在横向模式下预览 Compose 布局
- java - Apache Beam Pipeline 无法将数据插入 BigQuery。工作流失败
- jquery - swipeleft 事件上的 Jquery 不适用于我的 div 元素
- java - Telegram Bot - 如何从在组内发送消息的用户获取唯一 ID
- php - 如何使用 Cron 作业延迟将发布到数据库中的变量一分钟
- google-sheets - 如何在 ArrayFormula 中使用 COUNTA?
- javascript - removeEventListner 不工作。该怎么办?
- ibm-mq - 我可以在 Windows Container 中安装 IBMMQ 客户端吗?将 Windows 控制台应用程序(使用 IBM MQ 客户端)移动到 Windows 容器的最佳选择