2 回答
TA贡献1784条经验 获得超7个赞
// the Double value
Double someTime = 3.5;
// two ways of converting it to Duration
// (we need to use minutes because Duration.of expects a long, which cannot be fractional
Duration someDuration = Duration.ofMinutes((long) (someTime * 60));
Duration someDuration2 = Duration.of((long) (someTime * 60), ChronoUnit.MINUTES);
// convert the duration back to Double
Double someTimeAgain = (double)someDuration.toMinutes() / 60;
TA贡献1772条经验 获得超5个赞
我假设你的持续时间是小时数的两倍?然后你首先需要从中计算分钟数。这可能是 long durationInMinutes = durationFromDB * 60 或者,如果 0.5 是“半小时”,您需要先计算小时数,然后再计算分钟数并相加...所以 3.5h 是 180 分钟 + 30 分钟 = 210 分钟
然后你可以使用 java.time.Duration#ofMinutes(long minutes) 并得到你需要的。
添加回答
举报