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

后端 未结 11 1609
既然无缘
既然无缘 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 19:51

    var monthNames = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
    

    then just call monthNames[1] that will be Feb

    So you can always make something like

      monthNumber = "5";
      jQuery('#element').text(monthNames[monthNumber])
    

提交回复
热议问题