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

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

    why not use the built in "sec" . Here is an example :

    t1 = Time.now.sec 
    
    elapsed_t = Time.now.sec - t1
    
    puts "it took me :  #{elapsed_t} seconds to do something that is useful \n"
    

提交回复
热议问题