I’m aware of calculating number of days between two dates.
Java, Calculate the number of days between two dates
But i’m not able to understand how the calculation is made in below piece of code. Particularly the one which is highlighted below.
return (int)( (d2.getTime() - d1.getTime()) / (1000*60*60*24));
Kindly let me know the logic behind this.
The question you have linked has an answer from Jon Skeet. You should consider that. For your code, the difference between two dates is being returned in Millisecond. To convert into a single day the calculation is: