[Solved] How to print a localized date with only month and day (no year) in Java? [closed]


The Java locale framework supports internationalization of some common forms of date / time, numbers, currency and so on. For date / time values the set of predefined formats is described in the Java Tutorial: Using Predefined Formats.

Unfortunately, “year and month” is not one of the formats.

This leaves you with only one option. Write your code to support multiple formats, and select the most appropriate one based on the locale you are rendering / displaying for. By hand.


Speculation.

I can’t tell you why Java SE doesn’t support this, but I suspect that it is a combination of two things:

  • Very few applications would need this. The Java API designers are parsimonious … and tend to avoid “bloating” the APIs with support for features that are merely convenient for tiny minority of applications.

  • The conventions for displaying year / month are fluid. For instance, you say that the convention in the US is “May 2015”, but in some contexts it would be acceptable or even preferable to display as “2015, May”. In the face of this fluidity, I can understand why the Sun / Oracle engineers might not want to buy into the debate.

Having said that, it is possible to submit an RFE. (If you are prepared to wait years for a positive outcome.)

1

solved How to print a localized date with only month and day (no year) in Java? [closed]