Method: Time#usec

Defined in:
time.c

#usecInteger

Returns the number of microseconds in the subseconds part of self in the range (0..999_999); lower-order digits are truncated, not rounded:

t = Time.now # => 2022-07-11 14:59:47.5484697 -0500
t.usec       # => 548469

Related: Time#subsec (returns exact subseconds).

Returns:

[View source]

3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
# File 'time.c', line 3871

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));
}