Get first and last day of month using threeten, LocalDate

后端 未结 10 2497
鱼传尺愫
鱼传尺愫 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 15:02

    If anyone comes looking for first day of previous month and last day of previous month:

    public static LocalDate firstDayOfPreviousMonth(LocalDate date) {
            return date.minusMonths(1).withDayOfMonth(1);
        }
    
    
    public static LocalDate lastDayOfPreviousMonth(LocalDate date) {
            return date.withDayOfMonth(1).minusDays(1);
        }
    

提交回复
热议问题