Get month in mm format in javascript

前端 未结 9 995
悲&欢浪女
悲&欢浪女 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:31

    var CurrentDate = new Date();
        CurrentDate.setMonth(CurrentDate.getMonth());
    
        var day = CurrentDate.getDate();
        var monthIndex = CurrentDate.getMonth()+1;
        if(monthIndex<10){
            monthIndex=('0'+monthIndex);
        }
        var year = CurrentDate.getFullYear();
    
        alert(monthIndex);
    

提交回复
热议问题