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;

}

[787 byte] By [nmana_harish@hotmail.coma] at [2007-11-27 10:57:07]
# 1

Ok so what's the problem?

> The values I pass in are date1 ="12 Dec 2006 08:40"

> date2="11 Dec 2006 10:53" and

> I get output date1 is AFTER date2

12 Dec comes after 11 Dec

Message was edited by:

tjacobs01

tjacobs01a at 2007-7-29 12:07:16 > top of Java-index,Java Essentials,Java Programming...