你要实现的是不是当前月份和当前月份往前5个月,每个月的第一天是几号号最后一天是几号?如果是的话,我写了一个 能实现你的需求。你的问题让我好纠结。
$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代码,用于获取当前月份及其前五个月份每一天的具体日期,包括每个月的第一天和最后一天。该方法适用于需要按月处理日期范围的应用场景。

3759

被折叠的 条评论
为什么被折叠?



