【发布时间】:2011-04-29 23:48:10
【问题描述】:
我知道这会给我一个数字(11、21、23):
SimpleDateFormat formatDayOfMonth = new SimpleDateFormat("d");
但是如何格式化一个月中的某一天以包含 ordinal indicator、11th、21st 或 23rd?
【问题讨论】:
-
作为参考,这些被称为序数 - en.wikipedia.org/wiki/Ordinal_number_(linguistics)。
-
只是为了记录,任何构建响应而不是在表格中查找整个答案的东西几乎不可能本地化为其他语言。
-
答案有点不正确,请看我的答案。
-
现代评论:我建议你避免使用
SimpleDateFormat类。它不仅过时了,而且出了名的麻烦。今天我们在java.time, the modern Java date and time API 和它的DateTimeFormatter中做得更好。 -
查看数字 API (math.tools/api/numbers)。它支持序数、基数、用不同语言拼写的数字、用各种语言拼写为货币等。
标签: java date simpledateformat ordinal