Date Comparison
Please help me find the problem with the following code. It returns true sometimes and behaves okay at times.
The values I pass in are date1 ="12 Dec 2006 08:40"
date2="11 Dec 2006 10:53" and
formatString="dd MMM yyyy HH:mm"
I get output date1 is AFTER date2
private boolean greaterThan( String date1,String date2,String formatString)
{
SimpleDateFormat dateFormat = new SimpleDateFormat(formatString);
boolean retVal = false;
try
{
Date dt1 = dateFormat .parse(date1);
Date dt2 = dateFormat .parse(date2);
if (dt1.after(dt2))
{
retVal = true;
System.out.println("date1 is AFTER date2");
}
}
catch (ParseException ex)
{
}
return retVal;
}

