I need a cycle which iterates through dates interval
algorithm, date, java
Solution
ready to run ;-)
public static void main(String[] args) throws ParseException {
GregorianCalendar gcal = new GregorianCalendar();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd");
Date start = sdf.parse("2010.01.01");
Date end = sdf.parse("2010.01.14");
gcal.setTime(start);
while (gcal.getTime().before(end)) {
gcal.add(Calendar.DAY_OF_YEAR, 1);
System.out.println( gcal.getTime().toString());
}
}
Problem
I have the start date and the end date. I need to iterate through every day between these 2 dates. What's the best way to do this? I can suggest only something like: ``` Date currentDate = new Date (startDate.getTime ()); while (true) { if (currentDate.getTime () >= endDate.getTime ()) break; doSmth (); currentDate = new Date (currentDate.getTime () + MILLIS_PER_DAY); } ```