开发者

PHP date function showing wrong week

Why is PHP date("W") showing that the c开发者_如何学Current week is 2? Shouldn't it be on week 3?

In the PHP documentation it says: weeks starting on Monday. Does that mean it just ignored the first 3 days of this year?


No, week 2 is correct.

Week number according to the ISO-8601 standard, weeks starting on Monday. The first week of the year is the week that contains that year's first Thursday. The highest week number in a year is either 52 or 53.


2010-01-01 - 2010-01-03 are days in the 53th week that started on 2009-12-28.

edit: example script

$ts = strtotime('2009-12-27');
$end = strtotime('2010-01-26');

for($ts=strtotime('2009-12-27'); $ts<strtotime('2010-01-07'); $ts=strtotime('+1 day', $ts)) {
  echo date('Y-m-d W', $ts), "\n";
}

prints

2009-12-27 52
2009-12-28 53
2009-12-29 53
2009-12-30 53
2009-12-31 53
2010-01-01 53
2010-01-02 53
2010-01-03 53
2010-01-04 01
2010-01-05 01
2010-01-06 01


I believe this means that the first three days of the year belong to the 52nd week of last year.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜