获取两个日期之间的间隔天列表:
$begin = new DateTime( ‘2012-08-0‘ );
$end = new DateTime( ‘2012-08-31‘ );
$end = $end->modify( ‘+1 day‘ );
$interval = new DateInterval(‘P1D‘);
$daterange = new DatePeriod($begin, $interval ,$end);
foreach($daterange as $date){
echo $date->format("Ymd") . "<br>";
}
日期间隔月份:
$begin = new DateTime( ‘2012-08-01‘ );
$end = new DateTime( ‘2013-05-31‘ );
$end = $end->modify( ‘+1 month‘ );
$interval = new DateInterval(‘P1M‘);
$daterange = new DatePeriod($begin, $interval ,$end);
foreach($daterange as $date){
echo $date->format("Ym") . "<br>";
}
时间: 2024-10-16 23:26:06