How do I get the number of seconds between two DateTimes in Ruby on Rails

后端 未结 8 1744
庸人自扰
庸人自扰 2020-12-23 15:37

I\'ve got code that does time tracking for employees. It creates a counter to show the employee how long they have been clocked in for.

This is the current code:

8条回答
  •  独厮守ぢ
    2020-12-23 16:24

    there's a method made for that:

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

    equals 10.

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

    Hope I helped.

提交回复
热议问题