怎么获得本月起的未来12个月

WBOY
Release: 2016-06-13 13:31:22
Original
920 people have browsed it

如何获得本月起的未来12个月?

如何获得本月起的未来12个月?

我现在用的是:

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
for($i=1;$i'.$nextdate;
}

Copy after login


看起来似乎没问题,可打印后却发现3月份是重复的,不知是何原因。

2009-11
2009-12
2010-01
2010-03
2010-03
2010-04
2010-05
2010-06
2010-07
2010-08
2010-09
2010-10


------解决方案--------------------
因为 你的那个月份都是按30天算的 有的月份是28天的 所以等到了二月就不对了
------解决方案--------------------
PHP code

// 参数表示好多个月,你也可以修改为指定日期开始
function c($num = 12){
    $temp = array();
    $nowtime = strtotime( date('Y-m', time()) . '-1' );
    while( $num>0 ){
        $num--;
        $nowtime = strtotime( '+1 month', $nowtime );
        $temp[]  = date('Y-m', $nowtime);
    }
    unset( $num, $nowtime );
    return $temp;
}

print_r( c() ); <div class="clear">
                 
              
              
        
            </div>
Copy after login
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template