使用 Moment.js 按月份名称获取月份编号
Getting the month number by month name with Moment.js
我正在尝试 return 使用 MomentJS 传递月份名称的月份编号。例如,如果我将 "July" 传递给 moment() 我希望 7 被 returned.
阅读文档后,我尝试了几种不同的方法,这种方法很接近...
console.log(moment().month("July"));
在控制台中,隐藏在响应中我可以看到这个...
_monthsParse: Array[7]
谁能告诉我如何 return 正确使用 MomentJS 的月份数字?
尝试:
moment().month("July").format("M");
相关文档:http://momentjs.com/docs/#/get-set/month/
alert(moment().month("July").format("M"));
<script src="https://momentjs.com/downloads/moment.min.js"></script>
任何想从月份数字中获取月份名称的人都可以尝试:
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
```
要使用简单的月份数字试试这个:
const month = 2 //Feb
moment(month, 'M').format('MMMM');
我正在尝试 return 使用 MomentJS 传递月份名称的月份编号。例如,如果我将 "July" 传递给 moment() 我希望 7 被 returned.
阅读文档后,我尝试了几种不同的方法,这种方法很接近...
console.log(moment().month("July"));
在控制台中,隐藏在响应中我可以看到这个...
_monthsParse: Array[7]
谁能告诉我如何 return 正确使用 MomentJS 的月份数字?
尝试:
moment().month("July").format("M");
相关文档:http://momentjs.com/docs/#/get-set/month/
alert(moment().month("July").format("M"));
<script src="https://momentjs.com/downloads/moment.min.js"></script>
任何想从月份数字中获取月份名称的人都可以尝试:
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
```
要使用简单的月份数字试试这个:
const month = 2 //Feb
moment(month, 'M').format('MMMM');