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

time.to_i → int

Returns the value of time as an integer number of seconds since the Epoch.

If time contains subsecond, they are truncated.

Example
t = Time.now        #=> 2020-07-21 01:41:29.746012609 +0900
t.to_i              #=> 1595263289
See also #to_f #to_json #to_datetime #to_r also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.1