• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

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

 
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Result:

 
Antonio Giovanni
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
I don't even know how to spell CIA. But this tiny ad does:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic