Get Last Friday of Month in Java

后端 未结 16 1978
一生所求
一生所求 2020-11-28 11:28

I am working on a project where the requirement is to have a date calculated as being the last Friday of a given month. I think I have a solution that only uses standard Ja

16条回答
  •  佛祖请我去吃肉
    2020-11-28 11:50

    In Java 8, we can do it simply as:

    LocalDate lastFridayOfMonth = LocalDate
                                        .now()
                                        .with(lastDayOfMonth())
                                        .with(previous(DayOfWeek.FRIDAY));
    

提交回复
热议问题