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
time.c
View on GitHub ↗
static VALUE
time_minus(VALUE time1, VALUE time2)
{
struct time_object *tobj;
GetTimeval(time1, tobj);
if (IsTimeval(time2)) {
struct time_object *tobj2;
GetTimeval(time2, tobj2);
return rb_Float(rb_time_unmagnify_to_float(wsub(tobj->timew, tobj2->timew)));
}
return time_add(tobj, time1, time2, -1);
}
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