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

() -> ::Integer
to_i → integer

Returns the value of self as integer Epoch seconds; subseconds are truncated (not rounded):

Example
Time.utc(1970, 1, 1, 0, 0, 0).to_i         # => 0
Time.utc(1970, 1, 1, 0, 0, 0, 999999).to_i # => 0
Time.utc(1950, 1, 1, 0, 0, 0).to_i         # => -631152000
Time.utc(1990, 1, 1, 0, 0, 0).to_i         # => 631152000

Related: Time#to_f Time#to_r.

See also #to_f #to_r #to_datetime #to_s also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0