示例:
// String转YearMonth
String str = "2021-04";
YearMonth yearMonth = YearMonth.parse(str);
// YearMonth转String
str = DateTimeFormatter.ofPattern("yyyy年MM月").format(yearMonth);
System.out.println(str); //2021年04月
示例:
// String转YearMonth
String str = "2021-04";
YearMonth yearMonth = YearMonth.parse(str);
// YearMonth转String
str = DateTimeFormatter.ofPattern("yyyy年MM月").format(yearMonth);
System.out.println(str); //2021年04月