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

time - other_time → float
time - numeric → time

Returns a difference in seconds as a Float between time and other_time, or subtracts the given number of seconds in numeric from time.

Example
t = Time.now       #=> 2020-07-20 22:15:49.302766336 +0900
t2 = t + 2592000   #=> 2020-08-19 22:15:49.302766336 +0900
t2 - t             #=> 2592000.0
t2 - 2592000       #=> 2020-07-20 22:15:49.302766336 +0900
See also #+ #<=> .zone_utc? #asctime also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.1