MomentJS - 月份缩写



此方法有助于自定义月份缩写。

语法

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

示例

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

输出

Month Abbreviations

示例

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");

输出

momentToFormat

示例

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();

输出

monthsShort
momentjs_customization.htm
广告