Ordinal1.0.0+

  1. // From 2.12.0 onward
  2. moment.updateLocale('en', {
  3. ordinal : Function
  4. });
  5. // From 2.8.1 to 2.11.2
  6. moment.locale('en', {
  7. ordinal : Function
  8. });
  9. // Deprecated in 2.8.1
  10. moment.lang('en', {
  11. ordinal : Function
  12. });

Locale#ordinal should be a function that returns the ordinal for a given number.

  1. moment.updateLocale('en', {
  2. ordinal : function (number, token) {
  3. var b = number % 10;
  4. var output = (~~ (number % 100 / 10) === 1) ? 'th' :
  5. (b === 1) ? 'st' :
  6. (b === 2) ? 'nd' :
  7. (b === 3) ? 'rd' : 'th';
  8. return number + output;
  9. }
  10. });

As of 2.0.0, the ordinal function should return both the number and the ordinal. Previously, only the ordinal was returned.

As of 2.1.0, the token parameter was added. It is a string of the token that is being ordinalized, for example: M or d.

For more information on ordinal numbers, see Wikipedia.