In java, how can I find out if a specific date is within 1 year of today's date.
I have the following but not sure if this is the best approach.
String date = "01/19/2005";
DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
Date lastExamTakenDate = null;
Calendar todaysDateMinus1Year = Calendar.getInstance();
todaysDateMinus1Year.add(Calendar.YEAR, -1);
if (date!=null)
{
try {
lastExamTakenDate = df.parse(date);
if (lastExamTakenDate.before(todaysDateMinus1Year.getTime()))
hasToTakeExam = true;
} catch (ParseException ex) {
//exception
}
}