Android difference between two dates in seconds

You can turn a date object into a long (milliseconds since Jan 1, 1970), and then use TimeUnit to get the number of seconds:

long diffInMs = endDate.getTime() - startDate.getTime();

long diffInSec = TimeUnit.MILLISECONDS.toSeconds(diffInMs);

Edit:
-Corrected the name of the variable diffInMs which was written diffInM(i)s in the second line.

Leave a Comment