首页 > 解决方案 > 两个日期之间的持续时间 Java

问题描述

我有 DateTime 字符串 2020-04-03 01:29:27 和 2020-04-03 01:29:37 我想以小时为单位获得持续时间。我已经尝试了很多东西,但这却找不到任何帮助

标签: javadatetimebetweenduration

解决方案


I have tried many things but this but cant find any help

Do these "many things" include consulting the javadoc where you would find that:

// assuming both dates are in d1 and d2

Duration duration = Duration.between(d1, d2);

long hours = duration.toHours(); 

Hope that helps.


推荐阅读