Date.equals(Date) fails eventhough Date.toString() prints the same value

Hi All,

I have two dates inDate and outDate.

inDate is produced by parsing a string using SimpleDateFormat("yyyy-MM-dd hh:mm:ss")

outDate is produced by setting the Calendar Objects respective fields and then converted to a date using Date.get()

but inDate.equals(outDate) fails.... why...?

Eventhough .toString() call on both the dates produce the same value.....

Thanks

[416 byte] By [saracgia] at [2007-11-26 17:54:57]
# 1
Are you sure that the milliseconds are identical?Kaj
kajbja at 2007-7-9 5:08:03 > top of Java-index,Java Essentials,Java Programming...
# 2
In both the Strings, from which I compute inDate and outDate, I have not specified milliSeconds...toString() on both the dates prints these values respectivelyFri Feb 09 00:00:00 CET 2007Fri Feb 09 00:00:00 CET 2007
saracgia at 2007-7-9 5:08:03 > top of Java-index,Java Essentials,Java Programming...
# 3
Try calling getTime() on both Date objects to see if they are identical.
duckbilla at 2007-7-9 5:08:03 > top of Java-index,Java Essentials,Java Programming...
# 4
Hi Kajbj,I think you are right about the milliseconds...Date.getTime() on the dates prints slightly different values.....Once I solve it, i write how I solved it.thanks Kajbj
saracgia at 2007-7-9 5:08:03 > top of Java-index,Java Essentials,Java Programming...
# 5
duckbilll............. Thanks... I think we were writing messages at the same timethks anyway
saracgia at 2007-7-9 5:08:03 > top of Java-index,Java Essentials,Java Programming...
# 6

Solve it... Here is the soln.

In inDate, SimpleDateFormat.parse() sets milliseconds to 0 if not specified.. (I guess).

In outDate which I create using Calendar.set() of respective fields, I left out MILLISECOND until now.

Now I set it to 0 and it works..

Thanks all for support

saracgia at 2007-7-9 5:08:03 > top of Java-index,Java Essentials,Java Programming...
# 7
In case you didn't use ((Calendar)c).clear(), you might consider doing this before setting the time on it (e.g, c.set(year,month,day) )
javiousa at 2007-7-9 5:08:03 > top of Java-index,Java Essentials,Java Programming...