Get month name from Date

前端 未结 30 3350
情歌与酒
情歌与酒 2020-11-22 00:16

How can I generate the name of the month (e.g: Oct/October) from this date object in JavaScript?

var objDate = new Date(\"10/11/2009\");
30条回答
  •  轮回少年
    2020-11-22 01:05

    Store the names in a array and look up by the index of the month.

    var month=new Array(12);
    month[0]="January";
    month[1]="February";
    month[2]="March";
    month[3]="April";
    month[4]="May";
    month[5]="June";
    month[6]="July";
    month[7]="August";
    month[8]="September";
    month[9]="October";
    month[10]="November";
    month[11]="December";
    
    document.write("The current month is " + month[d.getMonth()]);
    

    JavaScript getMonth() Method

提交回复
热议问题