【发布时间】:2016-07-07 12:32:45
【问题描述】:
我认为我完全了解 ISO 8601,并且一年的第一周是其中有星期一的那一周。但是我在 PHP (5.6) DateTime 类中遇到了一个奇怪的行为。
这是我的代码:
$start = new DateTime('2009-01-01 00:00');
$end = new DateTime();
$point = $start;
while($point <= $end){
echo $point->format('YW');
$point = $point->modify('next week');
}
这输出正确
200901
200902
200903
...
但如果我选择 2008 年较早的日期作为开始日期,例如 $start = new DateTime('2008-01-01 00:00');,那么我会得到不同的结果:
...
200852
200801 // <=== 2008??
200902
200903
...
这是一个 PHP 错误还是我在这里遗漏了什么?
【问题讨论】:
-
因为它是 2009 年的第一周,请尝试
echo $point->format('YW') ." --> ". $point->format('Y-m-d');希望你会明白这件事
标签: php datetime week-number