- MomentJS Tutorial
- MomentJS - Home
- MomentJS - Overview
- MomentJS - Environment Setup
- MomentJS - Introduction
- MomentJS - Parsing Date And Time
- MomentJS - Date Validation
- MomentJS - Getter/Setter
- Manipulate Date And Time
- Formatting Date And Time
- MomentJS - Date Queries
- MomentJS - Internationalization
- MomentJS - Customization
- MomentJS - Durations
- MomentJS - Utilities
- MomentJS - Plugins
- MomentJS - Examples
- MomentJS Useful Resources
- MomentJS - Quick Guide
- MomentJS - Useful Resources
- MomentJS - Discussion
MomentJS - Ordinal
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
momentjs_customization.htm
Advertisements