$start_date = $this->_request->getParam("dateFrom", "");
$end_date = $this->_request->getParam("dateTo", "");
$date = array();
$startDate = strtotime($start_date);
$endDate = strtotime($end_date);
//这里是按每天遍历,所以每次增加 86400 60 * 60 * 24 = 86400
//for 循环
for ($i = $startDate; $i <= $endDate; $i += 86400) {
$date[] = date("Y-m-d", $i);
}
//while 循环
while ($startDate <= $endDate) {
$startDate += 86400;
$date[] = date("Y-m-d", $startDate);
}
//do while 循环
do {
$date[] = date("Y-m-d", $startDate);
} while (($startDate += 86400) <= $endDate);
print_r($date);
Array(
[0] => 2017-02-26
[1] => 2017-02-27
[2] => 2017-02-28
[3] => 2017-03-01
[4] => 2017-03-02
[5] => 2017-03-03
)
循环指定的时间段
最新推荐文章于 2021-10-16 21:44:35 发布