wood burning stoves 2.0*
The moose likes Java in General and the fly likes getTime() bug? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "getTime() bug?" Watch "getTime() bug?" New topic
Author

getTime() bug?

bab javier
Ranch Hand

Joined: Aug 12, 2003
Posts: 32
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

Joined: Nov 24, 2005
Posts: 14687
    
  16

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().


[My Blog]
All roads lead to JavaRanch
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41096
    
  44
Actually, being 0-based means the dates are June 31 and July 1st, but the reasoning still holds :-)


Ping & DNS - my free Android networking tools app
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

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

Joined: Oct 27, 2005
Posts: 19651
    
  18

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.)


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
wood burning stoves
 
subject: getTime() bug?
 
Similar Threads
Difference Between two dates
Number of days between the 2 given dates.
using Date and Calendar classes
how to measure the time to render a jsp
difference in weeks