MomentJS - Ordinal


Advertisements

The ordinal display for dates can be changed based on locale.

Syntax

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

Example

var localeData = moment.updateLocale('en', {
   ordinal: function (number, token) {
      var b = number % 10;
      var output = (~~(number % 100 / 10) === 1) ? 'th' :
      (b === 1) ? 'st' :
      (b === 2) ? 'nd' :
      (b === 3) ? 'rd' : 'TH';
      return number + output;
   }
});
var m = moment(['2015-05-8'], 'DD-MM-YYYY').format('Do');

In above example the th is changed to uppercase TH and the same is displayed in the output as the date is 8.

Output

Ordinal
momentjs_customization.htm
Advertisements