Difference in time between two dates in java

前端 未结 4 1982
礼貌的吻别
礼貌的吻别 2021-01-01 10:24

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

4条回答
  •  猫巷女王i
    2021-01-01 10:32

    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.

提交回复
热议问题