Get first and last day of month using threeten, LocalDate

后端 未结 10 2505
鱼传尺愫
鱼传尺愫 2020-12-07 14:06

I have a LocalDate which needs to get the first and last day of the month. How do I do that?

eg. 13/2/2014 I need to get 1/2/2014 and

10条回答
  •  天涯浪人
    2020-12-07 14:55

    Just use withDayOfMonth, and lengthOfMonth():

    LocalDate initial = LocalDate.of(2014, 2, 13);
    LocalDate start = initial.withDayOfMonth(1);
    LocalDate end = initial.withDayOfMonth(initial.lengthOfMonth());
    

提交回复
热议问题