我有下面的PHP代码:PHP环获得今天的日期和下面的9天
$date = new DateTime();
$date->setTimeZone(new DateTimeZone('America/New_York'));
$index = 0;
while($index <10){
$date->modify('+'. $index .' day');
print $date->format('Y-m-d') . ' - index: ' . $index . '<br/>';
$index++;
}
什么这个脚本应该做的事:应该显示在接下来的几天今天的日期和接下来的9个日期:(我每次都打印$ index值以确保索引始终正确)。
这实际显示:
2017-05-29 - index: 0
2017-05-30 - index: 1
2017-06-01 - index: 2
2017-06-04 - index: 3
2017-06-08 - index: 4
2017-06-13 - index: 5
2017-06-19 - index: 6
2017-06-26 - index: 7
2017-07-04 - index: 8
2017-07-13 - index: 9
注:了解如何从日期2017年6月1日跳到2017年6月4日再到2017-06- 08等。
我不知道为什么会发生这种情况,有人可以告诉我吗?这甚至是正确的方法吗?
这是正常它会打印2017-06-01,下一张是2017-06-04导致索引从1变为3!它就像增加3天而不是一个! –