Rails - Get the time difference in hours, minutes and seconds

前端 未结 5 1038
無奈伤痛
無奈伤痛 2020-12-15 16:17

I\'m looking for an idiomatic way to get the time passed since a given date in hours, minutes and seconds.

If the given date is 2013-10-25 23:55:00 and the current

5条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-15 16:58

    There's a method for that:

    Time.now.minus_with_coercion(10.seconds.ago)

    equals 10 (in fact, 9.99..., use .round if you want a 10).

    Source: http://apidock.com/rails/Time/minus_with_coercion

    Hope I helped.

提交回复
热议问题