End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
Time#nsec
time.nsec → int
time.c
View on GitHub ↗
static VALUE
time_nsec(VALUE time)
{
struct time_object *tobj;
GetTimeval(time, tobj);
return rb_to_int(w2v(wmulquoll(wmod(tobj->timew, WINT2WV(TIME_SCALE)), 1000000000, TIME_SCALE)));
}
Alias of #tv_nsec
Returns the number of nanoseconds for the subsecond part of time. The result is a non-negative integer less than 10**9.
Example
t = Time.now #=> 2020-07-20 22:07:10.963933942 +0900 t.nsec #=> 963933942
If time has fraction of nanosecond (such as picoseconds), it is truncated.
Example
t = Time.new(2000,1,1,0,0,0.666_777_888_999r) t.nsec #=> 666777888
Time#subsec can be used to obtain the subsecond part exactly.