Verified with Java SE 8 Update 211 released on April 17, 2019.
Sample.java
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("GGGGy year M month d day")
.withChronology(JapaneseChronology.INSTANCE)
.withLocale(Locale.JAPAN);
JapaneseDate jd = JapaneseDate.of(2019, 4, 29);
for (int i = 0; i < 5; i++) {
System.out.println(dtf.format(jd.plus(i, ChronoUnit.DAYS)));
}
Execution result
April 29, 2019
April 30, 2019
May 1, 1st year of Reiwa
May 2, 1st year of Reiwa
May 3, 1st year of Reiwa
It became Reiwa. You did it, did not you.
I was only concerned about the era, and I completely forgot to call the first year of the new era the "first year." I hope it doesn't cause any trouble.
Have a nice Golden Week.
Sample2.java
DateTimeFormatter dtf = new DateTimeFormatterBuilder()
.appendText(ChronoField.ERA, TextStyle.FULL)
.appendText(ChronoField.YEAR_OF_ERA, Collections.singletonMap(1L, "Former"))
.appendLiteral("Year")
.appendValue(ChronoField.MONTH_OF_YEAR)
.appendLiteral("Month")
.appendValue(ChronoField.DAY_OF_MONTH)
.appendLiteral("Day")
.toFormatter()
.withChronology(JapaneseChronology.INSTANCE)
.withLocale(Locale.JAPAN);
Would you like to make it the Christian era? (Conclusion)
Recommended Posts