1

Is there a way in Java you could format a date with the ordinal characters at the end of day

something like :

1st of july ?

I have searching all over and could not find it anywhere?

Hell Boy
  • 899
  • 5
  • 12
  • 22

1 Answers1

7

There is no automatic way I'm afraid. You need to use some kind of custom method. Here is one I used in the past:

String getOrdinal(final int day) {
    if (day >= 11 && day <= 13) {
        return "th";
    }
    switch (day % 10) {
        case 1: return "st";
        case 2: return "nd";
        case 3: return "rd";
        default: return "th";
    }
}
Guillaume
  • 22,694
  • 14
  • 56
  • 70