加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby – 为什么一年中的数字周从1或0开始,具体取决于年份?

发布时间:2020-12-16 21:20:41 所属栏目:百科 来源:网络整理
导读:为什么一年中的周数从2017年的1开始到2018年的0? Date.strptime('2017-01-01','%Y-%m-%d').strftime('%Y-%m-%d %U') #2017-01-01 01Date.strptime('2018-01-01','%Y-%m-%d').strftime('%Y-%m-%d %U') #2018-01-01 00 解决方法 从 Ruby docs Week number: Th
为什么一年中的周数从2017年的1开始到2018年的0?
Date.strptime('2017-01-01','%Y-%m-%d').strftime('%Y-%m-%d    %U') #2017-01-01    01
Date.strptime('2018-01-01','%Y-%m-%d').strftime('%Y-%m-%d    %U') #2018-01-01    00

解决方法

从 Ruby docs

Week number:

The week 1 of YYYY 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)

因此,Ruby似乎将“第一周”(第1周)标识为从今年的第一个星期日开始.在第0周之前发生的任何事情都发生在.2017年恰好在周日开始,所以第一天就开始了第一周.然而,2018年是在星期一开始的,因此2018年的第1周将从1月7日(即今年的第一个星期日)开始.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读