1. Member
Join Date
May 2010
Posts
4
Rep Power
0

I have the following method of an invoice object:

Java 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?

2. Senior Member
Join Date
Jun 2008
Posts
2,568
Rep Power
15
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.
Java Code:
`(30L * 24L * 60L * 60L * 1000L)`

3. Senior Member
Join Date
Jun 2008
Posts
2,568
Rep Power
15
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.

4. Member
Join Date
May 2010
Posts
4
Rep Power
0
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 ;)

5. Senior Member
Join Date
Jun 2008
Posts
2,568
Rep Power
15
I hope you'll understand that cross-posting is rude. Until then I think you can forget about any further help.

6. Member
Join Date
May 2010
Posts
4
Rep Power
0
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.

7. Senior Member
Join Date
Feb 2010
Location
Ljubljana, Slovenia
Posts
470
Rep Power
11
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.

8. Member
Join Date
May 2010
Posts
4
Rep Power
0
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.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•