我有LocalDate包含日期2012-12-28,我希望与本地的月名称(即十二月波兰)打印出来的所有格这在波兰是主格不同(grudnia和grudzień分别).因为我也想使用自定义格式,我创建了自己的DateTimeFormatter使用DateTimeFormatterBuilder(在Joda-Time中,AFAIK是正确的方式):
private static final DateTimeFormatter CUSTOM_DATE_FORMATTER
= new DateTimeFormatterBuilder()
.appendLiteral("z dnia ")
.appendDayOfMonth(1)
.appendLiteral(' ')
.appendText(new MonthNameGenitive()) // <--
.appendLiteral(' ')
.appendYear(4, 4)
.appendLiteral(" r.")
.toFormatter()
.withLocale(new Locale("pl", "PL")); // not used in this case apparently
Run Code Online (Sandbox Code Playgroud)
输出应为" z dnia 28 grudnia 2012 r. ".
我的问题是关于标有箭头的线:我应该如何实施MonthNameGenitive?目前它扩展DateTimeFieldType并且有很多代码:
final class MonthNameGenitive extends DateTimeFieldType {
private static final long serialVersionUID = 1L;
MonthNameGenitive() {
super("monthNameGenitive");
}
@Override
public …Run Code Online (Sandbox Code Playgroud)