• 05-09-2010, 10:32 PM
Sharke
I have the following method of an invoice object:

Code:

```public Date getDueDate()         {                 long current = invoiceDate.getTime();                 Date date =  new Date(current + (30 * 24 * 60 * 60 * 1000));                 return date;         }```
I mean to add 30 days to the invoice date and return that as the due date. However, the code above subtracts 30 days from the invoice date instead of adding it. Upon experimenting further I found that adding anything up to 24 days worth of milliseconds will add to the invoice date, whereas 25 days or over will be subtracted. Being new to Java I have absolutely no idea why this should be so or where I'm going wrong. Can anyone help?
• 05-09-2010, 11:34 PM
All of those numbers in the parens "(30 * 24 * 60 * 60 * 1000)" are integers, making the result an integer, which means a max value of 2,147,483,647 and that formula produces 2,592,000,000, so the value "overflows" and 2,147,483,648 is actually -2,147,483,648 making your result -444,516,352. Do that operation with longs, rather than integers, and you'll be okay. i.e.
Code:

`(30L * 24L * 60L * 60L * 1000L)`
• 05-09-2010, 11:43 PM
cross-posted
so I just wasted my time being nice and helpful enough to craft a detailed explanation and solution for you seeing as how you weren't mannered enough to alert the users here of your parallel thread.
• 05-09-2010, 11:48 PM
Sharke
Hey thanks for the answer! It all makes sense now. I'm sorry if the fact that I asked the question elsewhere affected you so emotionally, I hope one day you'll be able to get over it ;)
• 05-09-2010, 11:51 PM
I hope you'll understand that cross-posting is rude. Until then I think you can forget about any further help.
• 05-10-2010, 12:09 AM
Sharke
A simple "oh and by the way, cross posting is considered rude, please don't do it again" would have sufficed. But I guess overreacting is more fun, so whatever. Thanks for the answer though, I had been mistaken in thinking that there was some type conversion going on behind the scenes.
• 05-10-2010, 07:05 AM
m00nchile
Quote:

Originally Posted by Sharke
A simple "oh and by the way, cross posting is considered rude, please don't do it again" would have sufficed. But I guess overreacting is more fun, so whatever.

No, a simple "I posted this question on another forum" would have sufficed. Masijade was kind enough to voluntarily spend his time answering your question, when the question was already answered.
• 05-10-2010, 07:24 AM
Sharke
Quote:

Originally Posted by m00nchile
No, a simple "I posted this question on another forum" would have sufficed. Masijade was kind enough to voluntarily spend his time answering your question, when the question was already answered.

I explained exactly what happened - and why I'm not such an inconsiderate a-hole after all - on the other forum Masijade linked to, so I'm not going to bother going through all that rigmarole again. I still think he overreacted in a manner that was terse and unfriendly, but hey, that's pretty much par for the course in most programming forums. Newbies get snapped at for making some minor forum faux-pas, yada yada. Life goes on.