Print date in java with ordinals

Is there a way in Java that you could format the date with ordinals at the end of the day.

sort of:

July 1?

I searched everything and could not find it anywhere?

+1
source share
1 answer

I am not afraid of the automatic way. You need to use some kind of custom method. Here is the 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"; } } 
+6
source

Source: https://habr.com/ru/post/1380304/


All Articles