MomentJS - 月份名称



您可以在区域设置自定义中添加月份名称。

语法

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

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

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

示例

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

输出

Month Names

示例

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

输出

Month Names Update

示例

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

输出

Month Names Locale
momentjs_customization.htm
广告