Skip to content

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

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.

See also #tv_nsec #month #rfc2822 #monday? also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.1