使用序数字符在java中打印日期 [英] Printing date in java with ordinal characters

查看:119
本文介绍了使用序数字符在java中打印日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Java中是否有办法可以在一天结束时使用序数字符格式化日期

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

类似于:

7月1日?

我到处都搜索过,无法在任何地方找到它?

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

推荐答案

我害怕没有自动的方法。
您需要使用某种自定义方法。这是我过去使用的一个:

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";
    }
}

这篇关于使用序数字符在java中打印日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆