Error:

Get current time

t = Time.now # Refer to t.hour, t.min, t.sec 

Get current date

t = Time.now # Refer to t.year, t.month, t.day 

Convert date to epoch seconds

t = Time.new(2013, 11, 19, 23, 55, 55) # for local timezone
epoch = t.to_i # => 1384934155

Convert epoch seconds to date

t = Time.at(1384934155) # => 2013-11-19 23:55:55 -0800

Get timestamp

epoch = Time.now.to_i # => 1385424864

Add to date

today = Time.now # => 2013-11-25 16:15:10 -0800
tomorrow = today + (24*60*60) # => 2013-11-26 16:15:10 -0800

Substract from date

today = Time.now # => 2013-11-25 16:15:10 -0800
yesterday = today - (24*60*60) # => 2013-11-24 16:15:10 -0800

Difference between two dates

t1 = Time.new(2013, 11, 19, 23, 55, 55)
t2 = Time.new(2013, 11, 29, 23, 55, 55)
diff = t2 - t1 # => 864000.0

Get week number for the date

t = Time.new(2013, 11, 19, 23, 55, 55)
# See also %W and %U in documentation for more details
weekno = t.strftime("%V").to_i # => 47

Get day number in a year for the date

t = Time.new(2013, 11, 19, 23, 55, 55)
t.yday # => 323

Get day number in a week for the date

t = Time.new(2013, 11, 19, 23, 55, 55)
t.wday # => 2

Parse date from the string

string = "2013/11/19"
date = Date.strptime(string, "%Y/%m/%d")

Format date

t = Time.now
t.strftime("%Y/%m/%d, %A") # => "2013/11/25, Monday"

Sleep for number of seconds

sleep(10)

Sleep for less than a second

sleep(0.5)