Get month in mm format in javascript

前端 未结 9 990
悲&欢浪女
悲&欢浪女 2020-12-31 02:03

How do I retrieve the month from the current date in mm format? (i.e. \"05\")

This is my current code:

var currentDate = new Date();
va         


        
9条回答
  •  孤独总比滥情好
    2020-12-31 02:38

    If you do this

    var currentDate = new Date();
    var currentMonth = currentDate.getMonth() + 1;
    

    then currentMonth is a number, which you can format as you want, see this question that will help you with formatting: How can I format an integer to a specific length in javascript?

提交回复
热议问题