strftime("%U") and strftime("%W")
require "date"
t1 = Time.local(2002,5,1)
d1 = Date.new(2002,5,1)
week1a = t1.strftime("%U").to_i # 17
week1b = t1.strftime("%W").to_i # 17
week1c = d1.cweek # 18
t2 = Time.local(2005,5,1)
d2 = Date.new(2005,5,1)
week2a = t2.strftime("%U").to_i # 18
week2b = t2.strftime("%W").to_i # 18
week2c = d2.cweek # 17
Related examples in the same category