Heim  >  Artikel  >  Backend-Entwicklung  >  时间计算有有关问题啊列出最近的前后6个月

时间计算有有关问题啊列出最近的前后6个月

WBOY
WBOYOriginal
2016-06-13 10:14:22913Durchsuche

时间计算有问题啊...列出最近的前后6个月


$arr = array();
$nowd = date("Ym");
$arr[] = date("Ym",strtotime("-6 month"));
$arr[] = date("Ym",strtotime("-5 month"));
$arr[] = date("Ym",strtotime("-4 month"));
$arr[] = date("Ym",strtotime("-3 month"));
$arr[] = date("Ym",strtotime("-2 month"));
$arr[] = date("Ym",strtotime("-1 month"));

$arr[] = date("Ym");

$arr[] = date("Ym",strtotime("+1 month"));
$arr[] = date("Ym",strtotime("+2 month"));
$arr[] = date("Ym",strtotime("+3 month"));
$arr[] = date("Ym",strtotime("+4 month"));
  $arr[] = date("Ym",strtotime("+5 month"));
$arr[] = date("Ym",strtotime("+6 month"));

for($i=0;$i echo "".$arr[$i].",";
if($i%3==0)
echo '
';
}


?>

打印出来中间有2个 201203

201204不见了...

只有今天 2012 03 31 全天 的时候出现 平时都是正常的,求分析...

测试的时候请各位把日期设置为3.31号看看.

------解决方案--------------------
还是用你的代码

$nowd = date("Y-m-1");
把形如
$arr[] = date("Ym",strtotime("-6 month"));
都改成形如
$arr[] = date("Ym",strtotime("-6 month $nowd"));
就可以了

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn