//explain
public class DateLoop {
static String finalDate;
static String particularDate;
public static void main(String[] args) {
// TODO Auto-generated method stub
SimpleDateFormat sdf = new SimpleDateFormat("d-M-yyyy ");
Calendar cal = Calendar.getInstance();
particularDate = "2-1-2018";
// get starting date
cal.add(Calendar.DAY_OF_YEAR, -7);
// loop adding one day in each iteration
for(int i = 0; i< 7; i++){
cal.add(Calendar.DAY_OF_YEAR, 1);
finalDate =sdf.format(cal.getTime());
System.out.println(finalDate);
//ie, its giving previous 7 dates from present date, but I want
//particular date... thanks in advance
}
}
}
ie, its giving previous 7 dates from present date, but I want previous 7 dates from particular date.
particularDate
does nothing to the calendar instance. You have to actually set it to that date. – Bluefield