Skip to content

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

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