I want to iterate between two specific dates and store all the corresponding 10-minute values in an ArrayList. I followed the answers and code examples in the Get all full hours of every day of a year thread but I'm having problems in customizing the code to my needs. My code is the following so far:
final DateFormat df = DateFormat.getDateTimeInstance();
final Calendar c = Calendar.getInstance();
c.clear();
for (c.set(StringDateUtils.getYear(earliestKey), (StringDateUtils.getMonth(earliestKey) - 1),
StringDateUtils.getDayOfMonth(earliestKey), StringDateUtils.getHourOfDay(earliestKey),
StringDateUtils.getMinuteOfHour(earliestKey));
c.get(Calendar.YEAR) <= StringDateUtils.getYear(latestKey) &&
c.get(Calendar.MONTH) <= (StringDateUtils.getMonth(latestKey) - 1) &&
c.get(Calendar.DAY_OF_MONTH) <= StringDateUtils.getDayOfMonth(latestKey) &&
c.get(Calendar.HOUR) <= StringDateUtils.getHourOfDay(latestKey) &&
c.get(Calendar.MINUTE) <= StringDateUtils.getMinuteOfHour(latestKey);
c.add(Calendar.MINUTE, 10)) {
System.out.println(df.format(c.getTime()));
}
earliestKey contains a String with earliest Date and latestKey a String with the latest Date. StringDateUtils is a custom written class that contains all auxiliary methods to get the year, month etc from a String that is assembled in YYYYMMDD_HHMM fashion. I have also checked the values of earliestKey and latestKey to be valid in the aforementioned form and everything seems OK. The problem, as I can understand, is in the second part of the loop condition, the one that in the classic loop-iterations is the break-condition. I have tried '!=' instead of inequality, OR instead of AND operator but I can't get it to work. The following code snipped does not enter not even the first iteration.