我需要保持開始第一次迭代的開始日期常量,並將單位的結束日期添加,迭代應該發生,直到開始日期在結束數據之前。添加日期與恆定單位之間的差異
實施例:
開始時間(1/1/2015)和結束日期(12/31/2015)之間的差異爲12個月
和單元4個月
然後我應該得到
Contract Start date End date
1 1/1/2015 4/31/2015
2 5/1/2015 8/31/2015
3 9/1/2015 12/31/2015
CODE我已經試過:
private void contractDetails(List<PolicyPeriodFormulaType> policyPeriod){
for (PolicyPeriodFormulaType policyPeriodFormulaType : policyPeriod) {
Date effectiveDateFrom = policyPeriodFormulaType.getEffectivePeriod().getEffectiveFrom();
Date effectiveDateTo = policyPeriodFormulaType.getEffectivePeriod().getEffectiveTo();
Instant effectiveFrom = effectiveDateFrom.toInstant();
ZonedDateTime zdt = effectiveFrom.atZone(ZoneId.systemDefault());
LocalDate fromDate = zdt.toLocalDate();
Instant effectiveTo = effectiveDateTo.toInstant();
ZonedDateTime zdt1 = effectiveTo.atZone(ZoneId.systemDefault());
LocalDate toDate = zdt.toLocalDate();
int unit = policyPeriodFormulaType.getUnits();
String unitMeasurement = policyPeriodFormulaType.getUnitOfMeasurement();
Period p = Period.between(fromDate,toDate);
int months = p.getMonths();
int years = p.getYears();
if(unitMeasurement.equalsIgnoreCase("Month")){
months = months+(years*12);
}
int duration = months/unit; // 12/4 = 3
int i =0;
while(fromDate.isBefore(toDate)){
fromDate=fromDate;
toDate=fromDate.plusMonths(unit);
fromDate=toDate.plusMonths(unit);
}
}
}
@mikecat_mixc,你可以請告訴我,我要去哪裏錯了 –
你是什麼意思「你應該得到的」表你說你應該得到?你的代碼不輸出任何東西,所以我不知道你打算如何「獲取」該表。如果你只是在談論某些點的某些變量的值,那麼你並沒有告訴我們**在哪**點指出哪些**變量。 – ajb
我應該得到的手段,預期的輸出應該是像上面的表格。 –