time = Time.new
# Components of a Time
puts "当前时间 : " + time.inspect
puts time.year # => Year of the date
puts time.month # => Month of the date (1 to 12)
puts time.day # => Day of the date (1 to 31 )
puts time.wday # => 0: Day of week: 0 is Sunday
puts time.yday # => 365: Day of year
puts time.hour # => 23: 24-hour clock
puts time.min # => 59
puts time.sec # => 59
puts time.usec # => 999999: microseconds
puts time.zone # => "UTC": timezone name
# July 8, 2008Time.local(2008,7,8)# July 8, 2008, 09:10am, local timeTime.local(2008,7,8,9,10)# July 8, 2008, 09:10 UTCTime.utc(2008,7,8,9,10)# July 8, 2008, 09:10:11 GMT (same as UTC)Time.gm(2008,7,8,9,10,11)
now =Time.now # 当前时间
puts now
past = now -10# 10 秒之前. Time - number => Time
puts past
future = now +10# 10 秒之后. Time + number => Time
puts future
diff = future - past # => 10 Time - Time => 未来十秒和过去十秒的时间差
puts diff