2 回答

TA貢獻(xiàn)1784條經(jīng)驗(yàn) 獲得超7個(gè)贊
// 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貢獻(xiàn)1772條經(jīng)驗(yàn) 獲得超5個(gè)贊
我假設(shè)你的持續(xù)時(shí)間是小時(shí)數(shù)的兩倍?然后你首先需要從中計(jì)算分鐘數(shù)。這可能是 long durationInMinutes = durationFromDB * 60 或者,如果 0.5 是“半小時(shí)”,您需要先計(jì)算小時(shí)數(shù),然后再計(jì)算分鐘數(shù)并相加...所以 3.5h 是 180 分鐘 + 30 分鐘 = 210 分鐘
然后你可以使用 java.time.Duration#ofMinutes(long minutes) 并得到你需要的。
添加回答
舉報(bào)