End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
Time#tv_usec
time.tv_usec → int
time.c
View on GitHub ↗
static VALUE
time_usec(VALUE time)
{
struct time_object *tobj;
wideval_t w, q, r;
GetTimeval(time, tobj);
w = wmod(tobj->timew, WINT2WV(TIME_SCALE));
wmuldivmod(w, WINT2FIXWV(1000000), WINT2FIXWV(TIME_SCALE), &q, &r);
return rb_to_int(w2v(q));
}
Returns the number of microseconds for the subsecond part of time. The result is a non-negative integer less than 10**6.
Example
t = Time.now #=> 2020-07-20 22:05:58.459785953 +0900 t.usec #=> 459785
If time has fraction of microsecond (such as nanoseconds), it is truncated.
Example
t = Time.new(2000,1,1,0,0,0.666_777_888_999r) t.usec #=> 666777
Time#subsec can be used to obtain the subsecond part exactly.