如何在轨道中显示一年中剩余的几周?
答案 0 :(得分:2)
这里显然没有明确指定格式,但是这样的事情会显示当年剩下的每周的索引:
(Date.today.cweek..52).each { |w| puts w }
有关类似问题,请参阅Looping through weeks of the year in Ruby (Sinatra)
答案 1 :(得分:1)
(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