使用PHP获得几个月的特定时间段


Get months of certain time period with PHP

如何使用PHP检索2015年10月至2016年5月的所有月份?前2015年11月2015年12月2016年1月。。也是如此

PHP文档中有一个很好的例子。http://php.net/manual/en/class.dateperiod.php

<?php
$begin = new DateTime( '2012-08-01' );
$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>";
}
?>

只要提供所需的日期格式,您就完成了。

在此处更改:

$date->format("Ymd")

正如@Uchiha所说,这里有一个答案:https://stackoverflow.com/a/18743012/2160958