I'm trying to convert a Japanese date string to JapaneseDate.
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("Gyy年MM月dd日")
.withChronology(JapaneseChronology.INSTANCE)
.withResolverStyle(ResolverStyle.LENIENT);
JapaneseDate d = JapaneseDate.from(formatter.parse("平成01年01月01日"));
System.out.println(d);
System.out.println(d.format(formatter));
output:
Japanese Reiwa 71-01-01
令和71年01月01日
Since "令和元年" is "2019", "令和71年01月01日" is "2089-01-01". "平成01年01月01日" must be "1989-01-01".
How can I convert it correctly?
If I change the resolver style to ResolverStyle.STRICT
, it throws
java.time.format.DateTimeParseException: Text '平成01年01月01日'
could not be parsed: year, month, and day not valid for Era
If I change the resolver style to ResolverStyle.SMART
, it throws
java.time.format.DateTimeParseException: Text '平成01年01月01日'
could not be parsed: Invalid YearOfEra for Era: Heisei 101
ResolverStyle.STRICT
? – Tohubohujava.time.format.DateTimeParseException: Text '平成01年01月01日' could not be parsed: year, month, and day not valid for Era
. – GenniLocale.JAPAN
orLocale.JAPANESE
to.ofPattern()
. But nothing changes. – Genni