php DatePeriod类

获取一个日期列表

<?php

$start = new DateTime('2016-05-01');

//$interval  = new DateInterval('P1D'); //  P2W  正序日期,P1D间隔是天,P2W间隔是两周

$interval  = DateInterval::createFromDateString('-1 day'); // 倒序

$period  = new DatePeriod($start,$interval,3);

foreach ($period as  $dateTime) {

$date = $dateTime->format('Y-m-d');

echo $date;

echo "<br>";

}