如果我知道对于semi-monthly payment frequency,我应该总是使用每个月的1st和16th,给定第一个日期,我如何增加它?
这就是我到目前为止所知道的:
...
while(cnt.getAndIncrement() <= pmtNumber ) {
monthdate = incrementDateUsingPaymentFrequency(LocalDate.of(2018, 2, 1), PaymentFrequencyCodeEnum.SEMIMONTHLY);
//do something with this incremented month
}
...
public static LocalDate incrementDateUsingPaymentFrequency(LocalDate monthDate, PaymentFrequency paymentFrequency){
LocalDate incrementedDate = null;
if(paymentFrequency == PaymentFrequency.SEMIMONTHLY){
incrementedDate = monthDate.plusDays(monthDate.getDayOfMonth() == 1 ? 16 : 0);
}
return incrementedDate;
}我所期待的结果是:
02/01/2018
02/16/2018
03/01/2018
03/16/2018
04/01/2018
04/16/2018
...发布于 2019-02-28 00:46:21
因为我们知道semi-monthly只需要使用1st和16th。当日期是当月的日期时,只需添加15 1st即可。When is month (16th),add 1 month to date并返回当月的1st日。
if(paymentFrequency == PaymentFrequency.SEMIMONTHLY){
incrementedDate = monthDate.getDayOfMonth() == 1 ? monthDate.plusDays(15) : monthDate.plusMonths(1).withDayOfMonth(1);
}https://stackoverflow.com/questions/54909390
复制相似问题