如何在rails中显示一年的剩余周?
这里显然不需要指定格式,但是像这样的代码将显示一年中剩下的每一周的索引:
(Date.today.cweek..52).each { |w| puts w }
参见在Ruby (Sinatra)中循环一年中的周,了解类似的问题
(Date.today.cweek...Date.today.end_of_year.cweek)
编辑
(Date.today.cweek...Date.today.end_of_year.cweek).each_slice(2) do |weeks|
puts weeks.join("-")
end