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
- Time and Date Classes
- Parsing and Formatting
- Time Arithmetic
- Time Zones