• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getTime() bug?

 
bab javier
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys!

I'm kinda dazed by this. The Date getTime() is giving the same result for two different dates:


Result:
milliseconds1 = 1276849617164
milliseconds2 = 1277972817164
milliseconds3 = 1277972817164

milliseconds 2 and 3 have the same values.

Hope someone can explain why. Thanks.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Month is 0-based. Your code sets April 31(which does not exist) and May 1st. I think you want to do the following instead:


And you can use calendar1.getTimeInMillis() instead of calendar1.getTime().getTime().
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, being 0-based means the dates are June 31 and July 1st, but the reasoning still holds :-)
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:Actually, being 0-based means the dates are June 31 and July 1st, but the reasoning still holds :-)

Arrgghh, Mein Leben ! (Wolfenstein fans will understand)
 
Rob Spoor
Sheriff
Pie
Posts: 20512
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's why you should use the following:
No ambiguity there!

Bab, also don't use 06. That makes your number octal. 08 and 09 will not be what you expect. (In fact they are completely invalid numbers.)
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic