I am trying to compute a return date in milliseconds based on outgoing date in milliseconds and days in destination. I chose to do that by adding daysIn * 86400000 to outgoing date, where 86400000 represents a day in milliseconds.
long newReturn = newOut + (daysIn * 86400000);
The second part of this expression is seemingly not working. If I set daysIn to 30, daysIn * 86400000 is apparently -1702967296. I expect 2592000000 so this obviously causes my newReturn value to be wrong.
If the value is small, e.g. 2, it works fine so I don't understand this problem.
These are the types of variables:
long newReturn;
long newOut;
int daysIn;
I thought maybe there would be an issue with type but long can handle large numbers and it all works if daysIn is 24 or less. Any ideas on what can cause the error or how to fix it? Anything will be appreciated.