How do I get elapsed time in milliseconds in Ruby?

前端 未结 10 2159
走了就别回头了
走了就别回头了 2020-12-13 05:27

If I have a Time object got from :

Time.now

and later I instantiate another object with that same line, how can I see how many

10条回答
  •  粉色の甜心
    2020-12-13 05:59

    Try subtracting the first Time.now from the second. Like so:

    a = Time.now
    sleep(3)
    puts Time.now - a # about 3.0
    

    This gives you a floating-point number of the seconds between the two times (and with that, the milliseconds).

提交回复
热议问题