Home  >  Article  >  Backend Development  >  时间计算有有关问题啊列出最近的前后6个月

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

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

时间计算有问题啊...列出最近的前后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"));
就可以了

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn