ordinal


// 从 2.12.0 开始
moment.updateLocale('en', {
    ordinal : Function
});
// 从 2.8.1 至 2.11.2
moment.locale('en', {
    ordinal : Function
});

// 废弃于 2.8.1
moment.lang('en', {
    ordinal : Function
});

Locale#ordinal 应是一个返回给定数字序数的函数。

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

2.0.0 开始,序数函数应同时返回数字和序数。以前仅返回序数。

2.1.0 开始,添加了令牌参数。它是要排序的令牌的字符串,例如:Md

有关序数的更多信息,参阅 Wikipedia

// 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.