The code for calculating the date in milliseconds is:
//installment date converted to milliseconds
long localDateInstall = installDate.getTime();
//installment date converted to milliseconds
long localDatePay = payDate.getTime();
and here I calculate the number of days between these dates:
days=Math.abs((localDatePay - localDateInstall))/86400000;
When I want to test it, I enter 1/Jan/2012 for localDateInstall and 1/Feb/2012 for localDatePay. The result is: 29 Days. What is the problem? Thanks
Counter-example:
This works fine, and the output is “31”, as expected. The problem is somewhere in what you haven’t told us. Shot in the dark: you’re probably constructing your test input like this:
Sadly, that’s wrong in two ways. First, the “year” argument is supposed to be “the year minus 1900“. Second, January is month 0, not month 1. With those two dates as input, you would, indeed, get an answer of 29 because you’re actually asking it for the number of days in February of 3912, which is a leap year.