Get month name from Date

前端 未结 30 2945
情歌与酒
情歌与酒 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条回答
  •  梦毁少年i
    2020-11-22 01:03

    I heartily recommend the format function from, the moment.js library, which you can use like this:

    moment().format("MMM");  // "Apr" - current date
    moment(new Date(2012, 01, 04)).format("MMM");  // "Feb" - from a local date
    moment.utc(new Date(2012, 00, 04).format("MMM"); // "Jan" - from a UTC date
    

    Use "MMMM" instead of "MMM" if you need the full name of the month

    In addition to a lengthy list of other features, it has strong support for internationalization.

提交回复
热议问题