当我这样做时:
$date = "2017-02-06 21:30:00";
$end_date = "2017-02-28 21:30:00";
while (strtotime($date) <= strtotime($end_date)) {
echo $date."<br />";
$date = date("Y-m-d h:i:s", strtotime("+7 day", strtotime($date)));
}
我得到这个输出:
2017-02-06 21:30:00
2017-02-13 09:30:00
2017-02-20 09:30:00
2017-02-27 09:30:00
知道为什么 + 7 天短了 12 小时吗?
有区别
-
演出时间 01 至 12
date('h');
-
显示时间 00 至 23
date('H');
更多信息: http://php.net/manual/en/function.date.php
您的代码应该是:
$date = "2017-02-06 21:30:00";
$end_date = "2017-02-28 21:30:00";
while (strtotime($date) <= strtotime($end_date)) {
echo $date."<br />";
$date = date("Y-m-d H:i:s", strtotime("+7 day", strtotime($date)));
}
不是,你用 :
date("Y-m-d h:i:s",$time); // as h stands for 12-hour format of an hour with leading zeros 01 through 12
改用 H :
date("Y-m-d H:i:s",$time); // as H stands for 24-hour format of an hour with leading zeros 00 through 23