Basically, i want to set dates and save it to a list. From my code below:
public List<RecordList> createRecord(BigDecimal yr){
for (int index = 0; index <= 14; index++) {
RecordList value = new RecordList();
if(index == 0){
value.setStartDt(toDate(("01-04-" + yr)));
value.setEndDt(toDate(("30-04-" + yr)));
}
if(index == 1){
value.setStartDt(toDate(("01-05-" + yr.add(new BigDecimal(1)))));
value.setEndDt(toDate(("31-05-" + yr.add(new BigDecimal(1)))));
}
createRecord.add(newRecordValue);
return createRecord;
}
private Date toDate(String date) {
Date newDate = null;
try {
newDate = new SimpleDateFormat("dd-MM-YYYY").parse(date);
}
catch (ParseException e) {
e.printStackTrace();
}
return newDate;
}
what happens is, when I set the year to 2017, the output doesnt match with what I set:
"StartDate": "30-12-2017",
"EndDate": "30-12-2017"
and it doesnt increment to next year, instead it decrement to:
"StartDate": "30-12-2016",
"EndDate": "30-12-2016"