I'm displaying certain dates from an ArrayList and using a formatter to shorten the date to "dd/MM" but when I compare the dates it doesn't work for the months. e.g. 17/08 IS before 19/08, 21/08 IS after 19/08 but 17/09 IS before 19/08. What my program achieves is showing any of the dates within the next 8 days.
I've tried using .compareTo to do this and it works within a month but not going between months. I know it's comparing strings and I think that's the problem but I don't know how to get around it
SimpleDateFormat formatter = new SimpleDateFormat("dd/MM");
Calendar cal = Calendar.getInstance();
Date comDate = new Date();
cal.add(Calendar.DATE, 8);
//this adds days to the calender
comDate = cal.getTime();
String strDate = formatter.format(comDate);
//this applies the edited calender to the date I'm comparing to
ArrayList<String> arDat = new ArrayList<String>();
arDat.add("15/08");
arDat.add("15/09");
arDat.add("30/08");
Date recDate = new Date();
for (int i=0; i < arDat.size(); i++){
recDate = formatter.parse(arDat(i));
String strRecDate = formatter.format(recDate);
if (strRecDate.compareTo(strDate) < 0 {
showToast(recDate);
}
}
I want it to just show 15/08 but it shows 15/08 and 15/09