How to get the first date and last date of current quarter in java.util.Date

前端 未结 8 849

I need to get the first date of the current quarter as a java.util.Date object and the last date of the current quarter as a java.util.Date

8条回答
  •  不思量自难忘°
    2020-12-10 15:17

    It's pretty simple with LocalDate

    LocalDate inputDate = LocalDate.parse("2018-09-04");
    LocalDate firstDayOfQuarter = inputDate.withMonth(inputDate.get(IsoFields.QUARTER_OF_YEAR) * 3 - 2).with(TemporalAdjusters.firstDayOfMonth());
    LocalDate lastDayOfQuarter = inputDate.withMonth(inputDate.get(IsoFields.QUARTER_OF_YEAR) * 3).with(TemporalAdjusters.lastDayOfMonth());
    

    Cheers!

提交回复
热议问题