Get month name from Date

前端 未结 30 2886
情歌与酒
情歌与酒 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 00:43

    Unfortunately the best way to extract the month name is from the UTCString representation:

    Date.prototype.monthName = function() {
        return this.toUTCString().split(' ')[2]
    };
    
    d = new Date();
    //=> Thu Mar 06 2014 23:05:21 GMT+0000 (GMT)
    
    d.monthName();
    //=> 'Mar'
    

提交回复
热议问题