0

For Example, with a date of 02/01 without date suffix.

Given an input parameter of en_US(locale), it will return February 1st.

Given an input parameter of fr_CA(locale), it will return février 1er.

Given an input parameter of zh_CN(locale), it will return 二月 1日.

The thing that I really expect is date with suffix by locale. I have searched some java source online and I can get English date with suffix by doing something like this.

        switch (previousChar) {
            case '1': {
                return "th";
            }
            default: {
                switch (lastChar) {
                    case '1':
                        return "st";
                    case '2':
                        return "nd";
                    case '3':
                        return "rd";
                    default:
                        return "th";
                }
            }
        }

However, this is not enough. Because for different locales/languages, the suffix for date are different.

Any help will be really appreciated!

Frank
  • 21
  • 3
  • seems like java doesn't support this thing – xiumeteo Feb 17 '17 at 23:17
  • [“Ordinal”](https://en.wikipedia.org/wiki/Ordinal_indicator) is the technical term for the `st` & `rd` suffixes on the date numbers. Search Stack Overflow to find multiple existing Questions on this issue. Built-in classes do not provide [ordinal indicators](https://en.wikipedia.org/wiki/Ordinal_indicator), not even the nifty java.time classes offer that feature. – Basil Bourque Feb 18 '17 at 08:28

1 Answers1

0

Looks like Java doesn't support it but I googled it a little and you could do something like that using external libraries. Check out this link:

Joda DateTimeFormat with proper number suffix

Hope it helps.

Community
  • 1
  • 1
mlg
  • 5,248
  • 1
  • 14
  • 17