美文网首页
PHP计算近1年的所有月份

PHP计算近1年的所有月份

作者: yancolin | 来源:发表于2017-12-14 11:32 被阅读6次

<?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 />";
}
?>
效果图:

相关文章

网友评论

      本文标题:PHP计算近1年的所有月份

      本文链接:https://www.haomeiwen.com/subject/djohwxtx.html