gpt4 book ai didi

ruby-on-rails - 在 DateTime 减法中返回分钟

转载 作者:数据小太阳 更新时间:2023-10-29 07:59:14 24 4
gpt4 key购买 nike

以下返回 (5/12),一个 Rational 对象。

d = DateTime.current
d2 = d + 10.hours
d2 - d

我如何得到两个时间点的分钟差?

最佳答案

(d2 - d).class
=> Rational

Rational: A rational number can be represented as a paired integer number; a/b (b>0). Where a is numerator and b is denominator. Integer a equals rational a/1 mathematically.

d2 - d
=> (5/12) #get the number of days

((d2 - d) * 24 * 60).to_i
=> 600 # get the number of minutes

关于ruby-on-rails - 在 DateTime 减法中返回分钟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32783438/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com