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

前端 未结 8 863

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 14:55

    Pure Java-8+ solution:

    LocalDate localDate = LocalDate.now();
    LocalDate firstDayOfQuarter = localDate.with(localDate.getMonth().firstMonthOfQuarter())
        .with(TemporalAdjusters.firstDayOfMonth());
    
    LocalDate lastDayOfQuarter = firstDayOfQuarter.plusMonths(2)
        .with(TemporalAdjusters.lastDayOfMonth());
    

提交回复
热议问题