[英]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.