Win a copy of Microservices in Action this week in the Web Services forum!
  • 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:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!