MomentJS - Month Names


Advertisements

You can add month names to the locale customization.

Syntax

moment.updateLocale('en', {
   months : String[]
});

OR

moment.updateLocale('en', {
   months : Function
});

OR

moment.updateLocale('en', {
   months : {
      format : String[],
      standalone : String[]
   }
});

Example

var localeData = moment.updateLocale('fr', {
   months: [
      "Jan", "Feb", "Mar", "Apr", "May", "June", "July",
      "Aug", "Sept", "Oct", "Nov", "Dec"
   ]
});
var m = localeData.months();

Output

Month Names

Example

var localeData = moment.updateLocale('en', {
   nominative:
      'January_February_March_April_May_June_July_August_September_October_November_December'.split('_'),
   subjective: 
      'January_February_March_April_May_June_July_August_September_October_November_December'.split('_'),
   months: function (momentToFormat, format) {
      if (/^MMMM/.test(format)) {
         console.log(this._nominative);
         return this._nominative[momentToFormat.month()];
      } else {
         return this._subjective[momentToFormat.month()];
      }
   }
});
var m = localeData.months(moment(), "MMMM");

Output

Month Names Update

Example

var localeData = moment.updateLocale('en', {
   months : {
      format: 
         'January_February_March_April_May_June_July_August_September_October_November_December'.split('_'),
      standalone: 
         'January_February_March_April_May_June_July_August_September_October_November_December'.split('_'),
      isFormat:
         /D[oD]?(\[[^\[\]]*\]|\s+)+MMMM?|MMMM?(\[[^\[\]]*\]|\s+)+D[oD]?/ // from 2.14.0
   }
});
var m = localeData.months();

Output

Month Names Locale
momentjs_customization.htm
Advertisements