Ruby On Rails,周数不正确(-1)

我需要当前的周数,如果我没有完全弄错的话,现在是第51周? 但是,当在控制台中测试时,我得到了这个。

Time.now => 2013-12-19 11:08:25 +0100 Time.now.strftime('%U') => "50" Date.today => Thu, 19 Dec 2013 Date.today.strftime("%U").to_i => 50 

这是为什么?

Time.now.strftime('%V')将根据ISO 8601为您提供周数。

 why is that? 

根据%U%W ,第一周之前一年中的天数是在第0周(00..53)。

%V (正如@Graeme McLean所写),第一周之前一年的日子是在前一年的最后一周(01..53)。

从这里开始 。

嗯,我不确定为什么会这样,但为了使用Ruby得到正确的,我使用这个:

 require 'Date' week_number = Date.today.cweek #=> 51