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

后端 未结 8 1755
庸人自扰
庸人自扰 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:21

    Subtracting two DateTimes returns the elapsed time in days, so you could just do:

    elapsed_seconds = ((end_time - start_time) * 24 * 60 * 60).to_i
    

提交回复
热议问题