我需要保持开始第一次迭代的开始日期常量,并将单位的结束日期添加,迭代应该发生,直到开始日期在结束数据之前。添加日期与恒定单位之间的差异
实施例:
开始时间(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
我应该得到的手段,预期的输出应该是像上面的表格。 –