メモ
JSR-310の和暦、そのままprintすると「Japanese Heisei 27-04-08」な感じになっちゃう。
漢字で表示したいときはDateTimeFormatter
を使う。
package perfectjava.entity;
import java.time.chrono.JapaneseChronology;
import java.time.chrono.JapaneseDate;
import java.time.chrono.JapaneseEra;
import java.time.format.DateTimeFormatter;
import java.time.format.FormatStyle;
public class Foo {
public static void main(String[] args) {
DateTimeFormatter formatter = DateTimeFormatter
.ofLocalizedDate(FormatStyle.FULL)
.withChronology(JapaneseChronology.INSTANCE);
JapaneseDate date = JapaneseDate.now();
System.out.println(date); // Japanese Heisei 27-04-08
System.out.println(date.format(formatter)); // 平成27年4月8日
JapaneseDate jjugCccDate = JapaneseDate.of(JapaneseEra.HEISEI, 27, 4, 11);
System.out.println(jjugCccDate.format(formatter)); // 平成27年4月11日
}
}