怎么计算近1年的所有月份?php
$z = date('Y-m');$a = date('Y-m', strtotime('-12 months'));
$begin = new DateTime($a);
$end = new DateTime($z);
$end = $end->modify('+1 month');
$interval = new DateInterval('P1M');
$daterange = new DatePeriod($begin, $interval ,$end);
foreach($daterange as $date){
echo $date->format("Y-m") . "<br />";
}
2018-03------------2019-03
页:
[1]