PHP 的 strtotime() 出现这种情况咋解释

为什么 strftime 解析出来的第 0 周,用 strtotime 解析却失败?看 strtotime 的文档:
Description: ISO year with ISO weekFormat: YY "-"? "W" WExamples: "2008W27", "2008-W28"strtotime 里的「??-W??」格式,W 前面应该是 ISO Year、后面应该接 ISO Week。所以为什么要画蛇添足在「年」「周」前面写上「ISO」,是为了装逼显得自己很专业吗?我们来看 strftime 的文档:
%g Two digit representation of the year going by ISO-8601:1988 standards (see %V)%G The full four-digit version of %g%V ISO-8601:1988 week number of the given year, starting with the first week of the year with at least 4 weekdays, with Monday being the start of the week 01 through 53 (where 53 accounts for an overlapping week)你看,%Y 和 %G 出来的是两种「年」,%W 和 %V 出来的是两种「周」,加不加 ISO 确实是有区别的。strtotime 里的 W 前后需要的是 %G 和 %V 的输出。拿 %Y 和 %W 的输出写进去,可不就是拿前朝的剑斩本朝的官么?
echo strftime("%G-%V", strtotime("2016-01-01")); // 输出 2015-53echo strftime("%Y-%m-%d", strtotime("2015-W53")); // 输出 2015-12-28(当周第一天)即:公历的 2016 年 1 月 1 日,还在 ISO 2015 年的第 53 周(2015-12-28 ~ 2016-01-03)。
后面的疑问同理,ISO 年和公历的年不同、ISO 周和公历的周不同。
p.s. 关于问题里提到的「第 0 周」,其实你也用不着观察和猜想,看 strftime 的文档就可以知道标准答案了:
%W A numeric representation of the week of the year, starting with the first Monday as the first week.有疑问还是先看文档吧。

■网友
strptime — Parse a time/date generated with strftime()
■网友
【PHP 的 strtotime() 出现这种情况咋解释】 初步看了你这个问题的描述,应该是PHP的时区没有设置对,你打开php.ini文件,找到date.timezone这个配置,然后设置为date.timezone = Asia/Shanghai,就可以了。


    推荐阅读