Get localized month name using native JS

前端 未结 1 1597
青春惊慌失措
青春惊慌失措 2021-01-04 03:03

It\'s possible to do this to get the localized full month name using native javascript.

var objDate = new Date(\"10/11/2009\"),
    locale = \"en-us\",
    m         


        
相关标签:
1条回答
  • 2021-01-04 03:38

    You are already close:

    var getMonth = function(idx) {
    
      var objDate = new Date();
      objDate.setDate(1);
      objDate.setMonth(idx-1);
    
      var locale = "en-us",
          month = objDate.toLocaleString(locale, { month: "long" });
    
        return month;
    }
    
    console.log(getMonth(1));
    console.log(getMonth(12));

    0 讨论(0)
提交回复
热议问题