Tuesday, January 26, 2016

AngularJS displaying the date suffix - th, st, nd, rd

When displaying date times with AngularJS it is sometimes necessary (for design reasons) to display the date times suffix. That is the th, st, nd and rd element inside a date - Tuesday 26th January 2016 for example.

Out of the box there is no way to do this however there are custom directives/filters available online that make it simple to implement. An example is available on Plnkr which provides the date2 filter, which implments the data suffix via the custom date format "oo". For example {{dt|date2:'MMMM ddoo'}} filters the datetime to appear as Janurary 26th.

No comments:

Post a Comment