I have to sort through a Date[] and calculate what the largest span between entries is in days. The values are parsed to Date from string values (being passed from the database) An example date array would look like so:
Date[] myDateArray = {01/01/2014,03/01/2014,04/01/2014,07/01/2014,19/01/2014};
This is a snippet of my method.
temp = i_value = j_value = max = maxdiff = diff = 0;
for (int i = 0; i < dateValues.length; i++) {
for (int j = i + 1; j < dateValues.length; j++) {
cal.setTime(dateValues[i]);
i_value = (cal.get(Calendar.YEAR) * 365) + cal.get(Calendar.DAY_OF_YEAR);
cal.setTime(dateValues[j]);
j_value = (cal.get(Calendar.YEAR) * 365) + cal.get(Calendar.DAY_OF_YEAR);
max = Math.abs(i_value - j_value);
}
diff = Math.abs(max - max2);
if (maxdiff < diff) {
maxdiff = diff;
}
temp = maxdiff;
}
return temp;