Time and Date Classes
Working with time.
The Time Class
Ruby's built-in Time class represents a moment in time. Time.now gives the current time including date and clock.
t = Time.now
puts t.class
puts(t.year)Building a Specific Time
Time.new (or Time.local) builds a time from parts: year, month, day, hour, minute, second.
t = Time.new(2026, 5, 30, 14, 30, 0)
puts t.year
puts t.hour
puts t.minAll lessons in this course
- Time and Date Classes
- Parsing and Formatting
- Time Arithmetic
- Time Zones