javascript - 如何仅使用月份名称使用 MomentJS 设置完整日期?
问题描述
我想知道 MomentJS 是否有任何选项来设置完整日期,例如"2019-03-01T00:00:00.000Z"
使用月份的字符串名称Mar
我要做的是像这样获取所选月份的交易。但这仅适用于当月;
const month = moment.utc(); // here I would use something to define the selected month
const startMonth = moment(month).startOf("month");
const endMonth = moment(month).endOf("month");
const monthTransaction = getUserTransactions.filter(
transaction =>
transaction.createdAt > startMonth.toISOString() &&
transaction.createdAt < endMonth.toISOString()
);
解决方案
如果您有月份名称,则可以执行以下操作将其解析为时刻日期:
moment("Mar", "MMM")
有关解析选项的更多信息,请参见此处https://momentjs.com/docs/#/parsing/string/。
推荐阅读
- python - 根据间隔pyspark过滤数据框列中的值
- php - 如何将会话数据保存到数据库然后恢复它
- c# - 函数未在 C# 中执行
- javascript - java script game / 我想通过点击改变一个数字。我应该怎么办?
- python - 如何在 Pandas Python 中添加“子”数据帧或子行,每行和每个对象都有不同的操作?
- android - 努力使用 getByteArray 从 Bundle 中提取 ByteArray
- metadata - Google Optimize - 如何动态获取“测试描述”和其他测试元数据
- javascript - 使用 Storybook 渲染多个变体
- flutter - Dart:将文件的大小保持在一定大小而不截断
- python - Python datetime.fromisoformat() 拒绝 JavaScript 日期/时间字符串:ValueError: Invalid isoformat string