Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
Time#subsec
() -> (0 | ::Rational)
subsec → numeric
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 exact subseconds for self as a Numeric (Integer or Rational):
Example
t = Time.now # => 2022-07-11 15:11:36.8490302 -0500 t.subsec # => (4245151/5000000)
If the subseconds is zero, returns integer zero:
Example
t = Time.new(2000, 1, 1, 2, 3, 4) # => 2000-01-01 02:03:04 -0600 t.subsec # => 0