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

后端 未结 11 1648
既然无缘
既然无缘 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:16

    One more way to do the same

    month1 = month1.toLowerCase();
    var months = ["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"];
    month1 = months.indexOf(month1);
    

提交回复
热议问题