0Pricing
Ruby Academy · Lesson

Time Arithmetic

Durations and differences.

Adding Seconds to a Time

Time arithmetic works in seconds. Adding a number to a Time moves it forward by that many seconds.

t = Time.new(2026, 5, 30, 12, 0, 0)
later = t + 60
puts(later.min)

Subtracting Seconds

Subtracting a number moves a Time backward by that many seconds.

t = Time.new(2026, 5, 30, 12, 0, 0)
earlier = t - 3600
puts(earlier.hour)

All lessons in this course

  1. Time and Date Classes
  2. Parsing and Formatting
  3. Time Arithmetic
  4. Time Zones
← Back to Ruby Academy