joda time - add weekdays to date

前端 未结 5 1578
情书的邮戳
情书的邮戳 2020-11-30 15:11

Is it possible to add weekdays to joda time?

For instance, if current date is Friday 01/03, date + 1 should return Monday 04/03, rather than 02/03.

5条回答
  •  执笔经年
    2020-11-30 15:43

        public LocalDate getBusinessDaysAddedDate(LocalDate localDate, int businessDays){
    
            LocalDate result;
            if(localDate.getDayOfWeek().getValue() + businessDays > 5) {
                result = localDate.plusDays(2);
            }
            result = localDate.plusDays(businessDays);
    
            return result;
        }
    

    In order to work with Date instead of LocalDate, refer https://stackoverflow.com/a/47719540/12794444 for the conversions.

提交回复
热议问题