Easiest way to convert month name to month number in JS ? (Jan = 01)

后端 未结 11 1608
既然无缘
既然无缘 2020-11-27 19:21

Just want to covert Jan to 01 (date format)

I can use array() but looking for another way...

Any suggestion?

11条回答
  •  清酒与你
    2020-11-27 20:12

    If you don't want an array then how about an object?

    var months = {
        'Jan' : '01',
        'Feb' : '02',
        'Mar' : '03',
        'Apr' : '04',
        'May' : '05',
        'Jun' : '06',
        'Jul' : '07',
        'Aug' : '08',
        'Sep' : '09',
        'Oct' : '10',
        'Nov' : '11',
        'Dec' : '12'
    }
    

提交回复
热议问题