获取一月份的周数时输出不规则
Irregular output in getting the week number of January
谁能解释为什么会这样?
<?php
echo date("W", strtotime("2015-01-01"))."<br>"; //returns 1
echo date("W", strtotime("2014-01-01"))."<br>"; //returns 1
echo date("W", strtotime("2016-01-01"))."<br>"; //returns 53
?>
输出月中某天的周数时,某些情况下结果不正确。这里的输出,周数是 1,这对于前两种情况是正确的,但在第三种情况中不是。
它为 "2016-01-01"
输出 53 而不是 1 的原因是它从一年中的第一个星期一开始计算一年中的第一周,即 2016 年的 1 月 4 日(“2016 -01-04").
W ISO-8601 week number of year, weeks starting on Monday (added in PHP
4.1.0) Example: 42 (the 42nd week in the year)
查看 php 日期函数 here 的完整文档。
如前所述,W ISO-8601 年中的周数 是您得到的数字。
有关 W ISO-8601 年中周数的更多信息,请参阅下文,
An ISO week-numbering year (also called ISO year informally) has 52 or
53 full weeks. That is 364 or 371 days instead of the usual 365 or 366
days. The extra week is referred to here as a leap week, although ISO
8601 does not use this term. Weeks start with Monday. The first week
of a year is the week that contains the first Thursday of the year
(and, hence, always contains 4 January). ISO week year numbering
therefore slightly deviates from the Gregorian for some days close to
1 January.
Source: Wiki
2016-01-01属于2015年的最后一周,因为这一周是从那一年开始的,所以结果是正确的。
谁能解释为什么会这样?
<?php
echo date("W", strtotime("2015-01-01"))."<br>"; //returns 1
echo date("W", strtotime("2014-01-01"))."<br>"; //returns 1
echo date("W", strtotime("2016-01-01"))."<br>"; //returns 53
?>
输出月中某天的周数时,某些情况下结果不正确。这里的输出,周数是 1,这对于前两种情况是正确的,但在第三种情况中不是。
它为 "2016-01-01"
输出 53 而不是 1 的原因是它从一年中的第一个星期一开始计算一年中的第一周,即 2016 年的 1 月 4 日(“2016 -01-04").
W ISO-8601 week number of year, weeks starting on Monday (added in PHP 4.1.0) Example: 42 (the 42nd week in the year)
查看 php 日期函数 here 的完整文档。
如前所述,W ISO-8601 年中的周数 是您得到的数字。
有关 W ISO-8601 年中周数的更多信息,请参阅下文,
An ISO week-numbering year (also called ISO year informally) has 52 or 53 full weeks. That is 364 or 371 days instead of the usual 365 or 366 days. The extra week is referred to here as a leap week, although ISO 8601 does not use this term. Weeks start with Monday. The first week of a year is the week that contains the first Thursday of the year (and, hence, always contains 4 January). ISO week year numbering therefore slightly deviates from the Gregorian for some days close to 1 January.
Source: Wiki
2016-01-01属于2015年的最后一周,因为这一周是从那一年开始的,所以结果是正确的。