php 准确遍历时间(月份)

  1. function GetMonth($sign="1")  
  2. {  
  3.     //得到系统的年月  
  4.     $tmp_date=date("Ym");  
  5.     //切割出年份  
  6.     $tmp_year=substr($tmp_date,0,4);  
  7.     //切割出月份  
  8.     $tmp_mon =substr($tmp_date,4,2);  
  9.     $tmp_nextmonth=mktime(0,0,0,$tmp_mon+1,1,$tmp_year);  
  10.     $tmp_forwardmonth=mktime(0,0,0,$tmp_mon-1,1,$tmp_year);  
  11.     if($sign==0){  
  12.         //得到当前月的下一个月   
  13.         return $fm_next_month=date("Ym",$tmp_nextmonth);          
  14.     }else{  
  15.         //得到当前月的上一个月   
  16.         return $fm_forward_month=date("Ym",$tmp_forwardmonth);           
  17.     }  
  18. }  

 

http://alfred-long.iteye.com/blog/1613227

posted on 2016-10-31 14:26  fsgui  阅读(313)  评论(0编辑  收藏  举报