1. 程式人生 > >php獲取當前月份的前(後)幾個月

php獲取當前月份的前(後)幾個月

return php 得到 date code pre for style str

//獲取當前月份的前一月
function GetMonth($sign)  
{  
    //得到系統的年月  
    $tmp_date=date("Ym");  
    //切割出年份  
    $tmp_year=substr($tmp_date,0,4);  
    //切割出月份  
    $tmp_mon =substr($tmp_date,4,2);  
    // 得到當前月份的下幾月
    $tmp_nextmonth=mktime(0,0,0,$tmp_mon+$sign,1,$tmp_year);  
    // 得到當前月份的前幾月
    $tmp_forwardmonth=mktime(0,0,0,$tmp_mon-$sign,1,$tmp_year);  
        return $fm_next_month=date("Ym",$tmp_forwardmonth);          
    } 

php獲取當前月份的前(後)幾個月