1

The API dock states:
%U - Week number of the year. The week starts with Sunday. (00..53)
%W - Week number of the year. The week starts with Monday. (00..53)
ISO 8601 states that the first week of the year is the week that contains that year's first Thursday.
2013 starts on a Tuesday. Thus week 1 is that which starts with December 31, 2012 as week 1 (for %W)

Code:

my_date_variable.strftime("%W").to_i

is returning week # 1 as that starting January 7, 2013. Does not match what ISO 8601 would do.

4

1 回答 1

2

似乎你想要的是%Vruby​​ 支持的Date#strftime

> Date.parse("December 31, 2012").strftime("%V") => "01"

于 2015-02-06T19:43:20.680 回答