- 以下例子是没两天打印一次日期。
<?php
$dateStart = new \DateTime();
$dateInterval = \DateInterval::createFromDateString('-2 days');
$datePeriod = new \DatePeriod($dateStart,$dateInterval,30);
foreach ($datePeriod as $date){
echo $date->format('Y-m-d');
echo '<br>';
}
$begin = new DateTime( '2012-08-01' );
$interval = new DateInterval('P2D');
$daterange = new DatePeriod($begin, $interval ,15);
foreach($daterange as $date){
echo $date->format("Y-m-d") . "<br>";
}
image.png
网友评论