Greg Greg - 5 months ago 22
Java Question

java calendar display name style for day of month with ordinal indicator

Can Java be used to get different styles of day_of_month?

i.e. "21st" and "22nd" rather than just "21" and "22"?

also what are the 'st' and 'nd' at the end of dates called for future reference?

Answer

JDK (including Java 8) does not offer a solution out of the box, and other libraries like JodaTime also not. But you can look at this question on SO to get some ideas.

Furthermore, I think you can reasonably try your solution for ordinal day numbers only for English, but what about other languages? That is an important reason why no library can give support. In JodaTime or JSR-310 there might be an English-only handwritten solution possible on the base of introducing a specialized field, for example in JSR-310 the interface java.time.temporal.TemporalField, but this is surely a lot of work.