Moh*_*ami 0 ruby datetime ruby-on-rails-3
为什么当我使用
Time.now.strftime('%Y%W')
Run Code Online (Sandbox Code Playgroud)
或者
Date.today.strftime('%Y%W')
Run Code Online (Sandbox Code Playgroud)
他们返回 201912,而应该是 201913,因为我们现在是第 13 周,而不是第 12 周。
如何获取当前周数?
如果你查看文档,它是这样说的:
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)
Run Code Online (Sandbox Code Playgroud)
2019 年 1 月 1 日是星期二,因此本来是第 0 周 - 今天是第 12 周。
| 归档时间: |
|
| 查看次数: |
224 次 |
| 最近记录: |