以下返回 (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/