当我使用
Time.now.strftime('%Y%W')
Date.today.strftime('%Y%W')
方法返回201912,而应该是201913,因为我们在第13周,而不是12。
如何获取当前星期几?
答案 0 :(得分:3)
如果您查看文档,它会说:
Week number: The first week of YYYY that starts with a Sunday or
Monday (according to %U or %W). The days in the year before the first
week are in week 0.
%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)
2019年1月1日是星期二,所以应该是第0周-今天是第12周。
答案 1 :(得分:2)
Time.now.strftime('%Y%V')
将为您提供所需的输出。
%V-以周为基础的年份的周数(01..53)
您必须查找基于星期的年份。