strftime("%U") and strftime("%W") : strftime « Time « Ruby






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

1.Time#strftime directives
2.Time.gm(2006).strftime('The year is %Y!')
3.Format time as '%D'
4.Format time as '%d/%m/%y'
5.Format time as '%m/%d/%Y'
6.Format time as '%m-%d-%Y %H:%M:%S %Z'
7.Format time as '%m-%d-%Y %I:%M:%S %p'
8.Format time as '%A, %B %d, %Y'