[英]PHP strtotime bug help fix
$end = strtotime('2011-09-01');
$start = strtotime('today');
while($start > $end)
{
echo date('F Y', $start) . "<br>";
$start = strtotime("-1 month", $start);
}
结果:2014年4月2014年3月2014年3月2014年2月2014年1月2014年12月2013 ...等
我为什么要两次参加2014年3月? 如果有人可以提供帮助,谢谢。
我能够使用DateTime()
。 从结束日期开始,我从本月的第一天开始。 这使得每个月的天数无关紧要。 然后,我所要做的就是反转日期数组,使其符合您想要的格式。
$start = new DateTime('2011-09-01');
$end = new DateTime();
$interval = new DateInterval('P1M');
$period = new DatePeriod($start, $interval, $end);
$months= array();
foreach ($period as $dt) {
$months[] = $dt->format('F Y');
}
$months = array_reverse($months);
echo implode('<br>', $months);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.