Ordinal1.0.0+
// From 2.12.0 onward
moment.updateLocale('en', {
ordinal : Function
});
// From 2.8.1 to 2.11.2
moment.locale('en', {
ordinal : Function
});
// Deprecated in 2.8.1
moment.lang('en', {
ordinal : Function
});
Locale#ordinal
should be a function that returns the ordinal for a given number.
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;
}
});
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.
当前内容版权归 momentjs.com 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 momentjs.com .