• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

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.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!