Meaningless Drivel is fun!*
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: 14688
    
  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: 42923
    
  68
Actually, being 0-based means the dates are June 31 and July 1st, but the reasoning still holds :-)
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  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: 19784
    
  20

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: getTime() bug?