The code snippet will results in a boolean using which we can identify that given date is older than 900 days or not.
/**
* @param args
* @throws ParseException
*/
public static void main(String[] args){
// TODO Auto-generated method stub
boolean result = false;
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("ddMMyy");
simpleDateFormat.setLenient(false);
Date flightDateParsed = null;
try {
//Pass the date which we need to check
flightDateParsed = simpleDateFormat.parse("101111");
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//create Calendar instance
Calendar olderDate = Calendar.getInstance();
olderDate.add(Calendar.DATE, -900);
olderDate.set(Calendar.HOUR_OF_DAY, 0);
olderDate.set(Calendar.MINUTE, 0);
olderDate.set(Calendar.SECOND, 0);
olderDate.set(Calendar.MILLISECOND, 0);
if (flightDateParsed.before(olderDate.getTime())){
result = true;
}
System.out.println("True = Given Date is Older Than 900 days:::::"+result);
}