Reputation: 513
For some reasons using plusDays(1)
doesnt give me the correct answer. It increments the results instead by 1. What to change to make this code below work properly. Removing plusDays(1) doesnt seem to work. What am i doing wrong here.
It should output
September 13, 2016
September 14, 2016
September 15, 2016
and not
September 14, 2016
September 15, 2016
September 16, 2016
Code:
String startDate = "2016-09-13";
String endDate = "2016-09-15";
LocalDate start = LocalDate.parse(startDate);
LocalDate end = LocalDate.parse(endDate);
List<LocalDate> totalDates = new ArrayList<>();
while (!start.isAfter(end)) {
totalDates.add(start);
start = start.plusDays(1);
Milestones modelMilestones = new Milestones();
modelMilestones .setMilestone(start.toString("MMMM dd, yyyy"));
mDataList.add(modelMilestones);
}
Upvotes: 1
Views: 197
Reputation: 482
try like this once:
while (!start.isAfter(end)) {
totalDates.add(start);
Milestones modelMilestones = new Milestones();
modelMilestones .setMilestone(start.toString("MMMM dd, yyyy"));
mDataList.add(modelMilestones);
start = start.plusDays(1);
}
Upvotes: 4