我知道这会给我一个月中的日期作为数字(11,,,21)23:
11
21
23
SimpleDateFormat formatDayOfMonth = new SimpleDateFormat("d");
但是你如何格式化一个月中的一天以包含一个序数指示符,比如说11th,21st或23rd?
11th
21st
23rd
// https://github.com/google/guava import static com.google.common.base.Preconditions.*;
String getDayOfMonthSuffix(final int n) { checkArgument(n >= 1 && n <= 31, "illegal day of month: " + n); if (n >= 11 && n <= 13) { return "th"; } switch (n % 10) { case 1: return "st"; case 2: return "nd"; case 3: return "rd"; default: return "th"; } }