LocalDate必须有年,月,日三个内容

 

        //LocalDate -> YearMonth -> String
        LocalDate localDate = LocalDate.now();
        YearMonth yearMonth = YearMonth.of(localDate.getYear(), localDate.getMonthValue());
        String str = yearMonth.format(DateTimeFormatter.ofPattern("yyyyMM"));
        System.out.println(str);

 

 

     //String -> YearMonth -> LocalDate
        YearMonth yearMonth = YearMonth.parse("202008", DateTimeFormatter.ofPattern("yyyyMM"));
        LocalDate localDate = LocalDate.of(yearMonth.getYear(), yearMonth.getMonthValue(), 1);
        System.out.println(localDate.toString())

 

 

参考: https://blog.csdn.net/neweastsun/article/details/81702426    YearMonth

相关文章:

  • 2022-12-23
  • 2021-11-27
  • 2021-11-27
  • 2021-11-27
  • 2021-12-22
  • 2021-12-22
猜你喜欢
  • 2021-12-08
  • 2022-12-23
  • 2021-11-20
  • 2021-11-18
  • 2021-11-18
相关资源
相似解决方案