MomentJS - Month Abbreviation


Advertisements

This method helps in customizing the month abbreviations.

Syntax

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

Example

var localeData = moment.updateLocale('en', {
   monthsShort : ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
});
var m = localeData.monthsShort();

Output

Month Abbreviations

Example

var localeData = moment.updateLocale('en', {
   nominative:
      'Jan_Feb_Mar_Apr_May_June_July_Aug_Sept_Oct_Nov_Dec'.split('_'),
   subjective:
      'Jan_Feb_Mar_Apr_May_June_July_Aug_Sept_Oct_Nov_Dec'.split('_'),
   monthsShort:
      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.monthsShort(moment(), "MMMM");

Output

momentToFormat

Example

var localeData = moment.updateLocale('en', {
   monthsShort : {
      format: 
         'jan_feb_mar_apr_may_june_july_aug_sept_oct_nov_dec'.split('_'),
      standalone:
         'jan_feb_mar_apr_may_june_july_aug_sept_oct_nov_dec'.split('_')
   }
});
var m = localeData.monthsShort();

Output

monthsShort
momentjs_customization.htm
Advertisements