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 milliseconds have passed? The second object may be created that same minute, over the next minutes or even hours.
The proper way is to do a Time. now. getutc. to_i to get the proper timestamp amount as simply displaying the integer need not always be same as the utc timestamp due to time zone differences.
As stated already, you can operate on Time
objects as if they were numeric (or floating point) values. These operations result in second resolution which can easily be converted.
For example:
def time_diff_milli(start, finish) (finish - start) * 1000.0 end t1 = Time.now # arbitrary elapsed time t2 = Time.now msecs = time_diff_milli t1, t2
You will need to decide whether to truncate that or not.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With