This week's book giveaway is in the General Computing forum. We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line! See this thread for details.
Of course it doesn't mean you can't compare dates--it means if you do, and you're using its equals() method, that you have to follow its definition of equality.
James Dekker
Ranch Hand
Joined: Dec 09, 2006
Posts: 215
posted
0
David,
Thanks for looking into this... I don't have the spurious comma in my code.
I accidentally inserted it there when I was editing my posting.
Of course it doesn't mean you can't compare dates--it means if you do, and you're using its equals() method, that you have to follow its definition of equality.
Can you please elaborate on this?
By the way, I commented out the first test method and the second one failed as well (with the same type of failure message).
Could anyone please point me in the right direction? What am I possibly doing wrong?
Decided to use DateUtils.truncate() method from Apache Commons.
Here's the working code:
Now, if I break the test by setting DAY_OF_MONTH to 12, it displays this (take a look at the truncated seconds):
David thanks for all of your help and hopefully this posting will fall into the hands of someone else that might need compare dates using Java in the future!
It's simple. The test failed because the two dates you created were not equal.
You printed out parts of those two dates, and the parts you printed were equal. So it follows that the parts you didn't
print were not equal. Hence David's reference to "milliseconds"...