I have to find the difference in time between two different date objects in java and if that time exceeds 5 sec i have to invalidate the session.
Here\'s the scenari
From Java-8 onwards you may use-
ChronoUnit.DAYS.between(startDate.toInstant(), endDate.toInstant());
This is a generic Enum using which, it becomes pretty simple to find difference in any Unit.