Here, I am writing simple method to find out the number of days between two dates.
In many situations, we need to calculate it. So just pass two dates as parameters of the method and get the number of days in long data type.
public long getDateDiffString(Date date1, Date date2)
{
long time1 = date1.getTime();
long time2 = date2.getTime();
long aDay = 1000 * 60 * 60 * 24;
long noOfDays = (time2 - time1) / aDay;
if (noOfDays > 0) {
return noOfDays;
}
else {
noOfDays *= -1;
return noOfDays;
}
}
0 Comment(s)