美文网首页
php中如何获取最近六个月每个月的起始时间和结束时间 --- 2

php中如何获取最近六个月每个月的起始时间和结束时间 --- 2

作者: 一位先生_ | 来源:发表于2018-12-25 11:12 被阅读0次

$currentTime = time();

$cyear = floor(date("Y",$currentTime));

$cMonth = floor(date("m",$currentTime));

for($i=0;$i<6;$i++){

    $nMonth = $cMonth-$i;

    $cyear = $nMonth == 0 ? ($cyear-1) : $cyear;

    $nMonth = $nMonth <= 0 ? 12+$nMonth : $nMonth;

    $date = $cyear."-".$nMonth."-1";

    $firstday = date('Y-m-01', strtotime($date));

    $lastday = date('Y-m-t', strtotime($date));

    echo $cyear."年".$nMonth."月";

    echo "第一天:".$firstday;

    echo "最后一天:".$lastday,"";

}

相关文章

网友评论

      本文标题:php中如何获取最近六个月每个月的起始时间和结束时间 --- 2

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