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#usec

time.usec → int

Alias of #tv_usec

Returns the number of microseconds for the subsecond part of time. The result is a non-negative integer less than 10**6.

Example
t = Time.now        #=> 2020-07-20 22:05:58.459785953 +0900
t.usec              #=> 459785

If time has fraction of microsecond (such as nanoseconds), it is truncated.

Example
t = Time.new(2000,1,1,0,0,0.666_777_888_999r)
t.usec              #=> 666777

Time#subsec can be used to obtain the subsecond part exactly.

See also #tv_usec #utc #tv_sec #utc? also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.1