php 日期时间对象在尝试检索周数时的奇怪行为

Weird behavior of php datetime object when attempting to retrieve the week number

我有以下代码:

$d = new DateTime("2014-12-29");echo $d->format("W"); 

为什么 php 回显 01 而不是 52? 如果我写:

$d = new DateTime("2014-12-28");echo $d->format("W");

然后它像我期望的那样回显 52。

W 是 ISO-8601 周 (http://en.wikipedia.org/wiki/ISO_week_date),不一定 符合您的预期。

The ISO 8601 definition for week 01 is the week with the year's first Thursday in it.

...

If 1 January is on a Monday, Tuesday, Wednesday or Thursday, it is in week 01. If 1 January is on a Friday, it is part of week 53 of the previous year; if on a Saturday, it is part of week 52 (or 53 if the previous year was a leap year); if on a Sunday, it is part of week 52 of the previous year.