从两位数的月份号中获取月份名称 [英] Get month name from two digit month number

查看:79
本文介绍了从两位数的月份号中获取月份名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从两位数的月份号(例如09)中获得月份名称.我尝试使用此代码.但这是行不通的.该代码仅给出当前月份的名称.正确的代码是什么?

I want to get month name from two digit month number (ex- 09). I tried with this code. But it doesn't work. The code give current month name only. What are the correct code for it?

 var formattedMonth = moment().month('09').format('MMMM');

推荐答案

创建Moment对象时要传递月份:

You want to pass the month when you create the Moment object:

var formattedMonth = moment('09', 'MM').format('MMMM'); // September

moment(
    '09',           // Desired month
    'MM'            // Tells MomentJs the number is a reference to month
).format('MMMM')    // Formats month as name

这篇关于从两位数的月份号中获取月份名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆