【发布时间】:2021-11-21 16:08:40
【问题描述】:
我需要使用 date-fns 库从月份名称中获取月份索引号。之前我使用moment.js,使用moment.js 很简单
moment().month('March').format('M');
// Month name will be variable and I don't want to use static dictionary to get index number
如何使用date-fns 库实现相同的功能?我想使用format(date, 'M');,但它需要完整的日期,并且只有月份名称可用。
请提出建议。谢谢!
【问题讨论】:
-
我认为 date-fns 目前没有类似的东西 github.com/date-fns/date-fns/blob/master/src/getMonth/index.ts
标签: javascript date-fns