Currently, we have to take an indirect way to get unix_time in milliseconds.
time = Time.now milliseconds = (time.to_i * 1000) + (time.usec / 1000.0).round
I think it would be convenient if
Time#to_i accepts unit parameter like following.
time = Time.now milliseconds = time.to_i(:millisecond)
Updated by david_macmahon (David MacMahon) over 5 years ago
How about a more general
scale(or passing nothing) would return seconds.
scalewould return milliseconds.
1/60rfor scale would return minutes.
Masaki Matsushita wrote:
milliseconds = (time.to_i * 1000) + (time.usec / 1000.0).round
IMHO, it is generally preferable to avoid time travel by truncating to the beginning of the "present" millisecond rather than possibly rounding to the beginning of the "future" millisecond.
Updated by akr (Akira Tanaka) over 3 years ago
- Status changed from Open to Rejected
We have Process.clock_gettime since Ruby 2.1.
% ruby -e 'p Process.clock_gettime(Process::CLOCK_REALTIME, :millisecond)' 1478362786099
This can be used as Time.now.to_i(:millisecond) which is shown in this issue.
If it is not enough, please reopen.