我想要一個沒有年份的DateTimeFormat.shortDate()
,所以在德語中它將顯示爲02.01,英文中顯示爲01/02。DateTimeFormat shortDate without year
現在我正在使用以下內容。
return DateTimeFormat.shortDate()
.withLocale(Locale.getDefault())
.print(dateTime);
如何避免讓DateTimeFormat
打印出年?
我想要一個沒有年份的DateTimeFormat.shortDate()
,所以在德語中它將顯示爲02.01,英文中顯示爲01/02。DateTimeFormat shortDate without year
現在我正在使用以下內容。
return DateTimeFormat.shortDate()
.withLocale(Locale.getDefault())
.print(dateTime);
如何避免讓DateTimeFormat
打印出年?
你的問題已經在這裏回答:
Localised Date format without year with Joda Time
至少有一個很好的例子,如何處理您的問題。
如果你知道你將只支持某些地區的另一個選項,您可以用所需的格式,比如讓自己的地圖:
Map<Locale, DateTimeFormatter> formats = new HashMap<>();
formats.put(Locale.US, DateTimeFormat.forPattern("dd/MM"));
formats.put(Locale.GERMAN, DateTimeFormat.forPattern("MM.dd"));
DateTimeFormatter dateTimeFormatter = Optional.ofNullable(formats.get(Locale.getDefault()))
.orElse(DateTimeFormat.forPattern(DEFAULT_PATTERN));
dateTimeFormatter.print(DateTimeUtils.today());
歡迎來到StackOverflow!一旦你有15個聲望,你就可以將帖子標記爲重複。這是在這種情況下要做的事情。你不應該發佈一個包含這種東西的答案:) – Michael
好的,謝謝你的信息,將盡我所能。 –
您在德國02.01和英語01/02 – LLL
的意思是惋惜。混合起來。 – Niklas
[Joda時間沒有年份的本地化日期格式]的可能重複(http://stackoverflow.com/questions/33168198/localised-date-format-without-year-with-joda-time) –