3

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?

Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154
Greg
  • 754
  • 9
  • 18
  • I'm not aware of anything in stock JDK APIs to do this. If you google around you'll find several folks who have implemented one-offs like http://r3dux.org/2011/10/how-to-get-human-friendly-dates-in-java-using-the-calendar-class/ – Bob Kuhar Apr 05 '14 at 21:19
  • 2
    The "st" and "nd" at the end are called [ordinal indicators](http://en.wikipedia.org/wiki/Ordinal_indicator) – azurefrog Apr 05 '14 at 21:21

2 Answers2

3

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.

Community
  • 1
  • 1
Meno Hochschild
  • 42,708
  • 7
  • 104
  • 126
  • Looks like I'll have to do it the hard way, id rather not have any more API's than what is needed. – Greg Apr 05 '14 at 21:25
0

No you may need to write a small utility function which will help you achieving the same in Java

you ca refer SO Answer here for the same here

Community
  • 1
  • 1
dev2d
  • 4,245
  • 3
  • 31
  • 54