Skip to content

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

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
See also #strftime #sunday? #sec #thursday? also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0