Momentjs 使用Moment.js按月份名称获取月份编号

Momentjs 使用Moment.js按月份名称获取月份编号,momentjs,Momentjs,我尝试使用MomentJS返回通过月份名称的月份号。例如,如果我将“July”传递给moment(),我希望返回7 看完这些文档后,我尝试了几种不同的方法,这种方法很接近 console.log(moment().month("July")); 在控制台中,在回应中我可以看到这个 _monthsParse: Array[7] 有人能告诉我如何正确使用MomentJS返回月号吗?试试: moment().month("July").format("M"); 相关文件: alert(mome

我尝试使用MomentJS返回通过月份名称的月份号。例如,如果我将“July”传递给moment(),我希望返回7

看完这些文档后,我尝试了几种不同的方法,这种方法很接近

console.log(moment().month("July"));
在控制台中,在回应中我可以看到这个

_monthsParse: Array[7]
有人能告诉我如何正确使用MomentJS返回月号吗?

试试:

moment().month("July").format("M");
相关文件:

alert(moment().month(“July”).format(“M”)

任何想要从月号中获取月名的人都可以尝试:

const number = 1; // 0 = Jan & 11 = Dec
moment().month(number).format("MMM"); // Feb
使用以下命令获取完整的月份名称:

const number = 1; // 0 = January & 11 = December
moment().month(number).format("MMMM"); // February

加上一个。。有趣的是,这正是我所寻找的,我只是检查了这个问题,以得到一个想法。
##get month name in moment js with node js 
moment() give today date
format("DD-MMMM-YYYY") / output 18-May-2020
format("DD-MM-YYYY")  / output 18-05-2020
- sperator you can use / 

```
var moment = require('moment'); 

   m_date = moment().format("DD-MMMM-YYYY");
   console.log("moment date :", m_date)
```
##output
```
moment date : 18-May-2020

```