0Pricing
Ruby Academy · Lesson

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.min

All lessons in this course

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