我想知道 MomentJS 是否有任何选项可以使用 Mar 等月份的字符串名称设置完整日期,例如
"2019-03-01T00:00:00.000Z"
我想做的是像这样获取所选月份的交易。但这仅适用于当前月份;
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/有关解析选项的更多信息。
关于javascript - 如何仅使用月份名称来使用 MomentJS 设置完整日期?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55022815/