• Post Reply Bookmark Topic Watch Topic
  • New Topic

what's wrong with this,.. Date, Calendar Stuff.. ????  RSS feed

 
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,..

I am damn confused by the result of my code..



The values of all 3 Dates happens to be the same.

BUT the boolean results of both the IF conditions is Different. why??

I thought both the IF condition results should be the same..

Please let me know what is going wrong??
Appreciate your help..

DAMN !!.. this is really crazy..
 
Antonio Giovanni
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Result:

 
Antonio Giovanni
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ohhh yeah,..

the constructor



So using the before, after, compareTo, you cannot compare just the Dates..

Maybe i will format the Date instance to String object using SimpleDateFormat and then compare for dates..

your opinions ???
 
Ranch Hand
Posts: 410
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm sure the key to this lies in the 'millisecond precision'. Your Date objects are created in sequence and most likely differ only by a millisecond or two - if that. So when you print them out showing only hours, minutes, and seconds as you have, they appear to have the same value. But because the compare method works at a millisecond level, they are correctly determined to be different in the if statements.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!