How to parse

我只是一个虾纸丫 提交于 2019-12-01 03:51:51

It is achieved by utilizing DateTimeFormatter in the following manner;

DateTimeFormatter japaneseEraDtf = DateTimeFormatter.ofPattern("GGGGy年M月d日")
        .withChronology(JapaneseChronology.INSTANCE)
        .withLocale(Locale.JAPAN);

where GGGG in the pattern is the designator for the Japanese characters representing the era
(e.g. 平成 Heisei), and the rest with year/month/day values with their respective Japanese characters: y年 for year, M月 for the month, d日 for the day.

LocalDate.parse("明治23年11月29日", japaneseEraDtf);
LocalDate.parse("昭和22年5月3日", japaneseEraDtf);
LocalDate.parse("令和5年1月11日", japaneseEraDtf);

will give out;

1890-11-29
1947-05-03
2023-01-11

For LocalDateTime, by using the updated pattern "GGGGy年M月d日(E)HH時mm分" in japaneseEraDtf;

LocalDateTime.parse("平成23年3月11日(金)14時46分", japaneseEraDtf);

will result in;

2011-03-11T14:46
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!