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

WBOY
發布: 2016-06-13 13:31:22
原創
892 人瀏覽過

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

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

我现在用的是:

PHP code
<!--

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

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

登入後複製


看起来似乎没问题,可打印后却发现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>
登入後複製
相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!