End of Life Ruby 3.1 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
Time#subsec
time.subsec → number
time.c
View on GitHub ↗
static VALUE
time_subsec(VALUE time)
{
struct time_object *tobj;
GetTimeval(time, tobj);
return quov(w2v(wmod(tobj->timew, WINT2FIXWV(TIME_SCALE))), INT2FIX(TIME_SCALE));
}
Returns the subsecond for time.
The return value can be a rational number.
Example
t = Time.now #=> 2020-07-20 15:40:26.867462289 +0900 t.subsec #=> (867462289/1000000000) t = Time.now #=> 2020-07-20 15:40:50.313828595 +0900 t.subsec #=> (62765719/200000000) t = Time.new(2000,1,1,2,3,4) #=> 2000-01-01 02:03:04 +0900 t.subsec #=> 0 Time.new(2000,1,1,0,0,1/3r,"UTC").subsec #=> (1/3)