MomentJS - Weekday Names


Advertisements

This method helps in customizing the weekdays names as per locale.

Syntax

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

Example

var localeData = moment.updateLocale('en', {
   weekdays: [
      "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
   ]
});
var m = localeData.weekdays();

Output

localeData

Example

var localeData = moment.updateLocale('en', {
   weekdaysarray: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
   weekdays: function (momentToFormat, format) {
      return this._weekdaysarray[momentToFormat.day()];
   }
});
var m = localeData.weekdays(moment(), "");

Output

weekdaysarray

Example

var localeData = moment.updateLocale('en', {
   weekdays: {
      standalone:
         "Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split('_'),
      format:
         "Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split('_'),
      isFormat:
         /\[ ?[Вв] ?(?:прошлую|следующую|эту)? ?\] ?dd/
   }
});
var m = localeData.weekdays();

Output

Weekdays Method
momentjs_customization.htm
Advertisements