In android how to get difference between two dates?
Assume that two dates are d1, and d2.
long dif_dates = d1.getTime() - d2.getTime();
long secs = dif_dates / 1000;
long mins = seconds / 60;
long hours = minutes / 60;
long days = hours / 24;
assume that you have two dates secondDate and firstDate.
long dateDif = secondDate.getTime() - firstDate.getTime();
long difference = TimeUnit.MILLISECONDS.toSeconds(dateDif);
both are true. But second option gives difference in terms of seconds, where as first one in terms of days, hours.
Back To Top