Is there a way to format a day and month (in compact form), but not year, in the locale-correct order in Java/Kotlin? So for English it should be "Sep 20" but for Swedish "20 sep.".
For comparison, on Cocoa platforms, I can do the following (in Swift):
let formatter = DateFormatter()
formatter.locale = Locale(identifier: "sv_SE")
formatter.setLocalizedDateFormatFromTemplate("MMM d")
print(formatter.string(from: Date()))
This will correctly turn things around. Is there an equivalent thing to do with the Java SDKs? I've been trying various forms with both DateTimeFormatter
and the older SimpleTimeFormat
APIs, but no success.
Notes: Unlike this question, I don't want the full medium format that includes the year. I also don't want either DateTimeFormatter.ofPattern("MMM d")
, since that gives the incorrect result in Swedish, or DateTimeFormatter.ofPattern("d MMM")
, since that gives the incorrect result in English.
MonthDay
class to represent a month and day without a year. Unfortunately, the automatic localization features of java.time do not currently extend to this particular class, where we callDateTimeFormatter.ofLocalized…
. – Ramonitaramos