php获取当前月份,上一个月份,上两个月份,上三个月份

来源:互联网 发布:无法加载 windows 安装 编辑:程序博客网 时间:2024/05/16 19:40
$cur_month=(string)to_date(TIME_UTC,'Y-m');

// $last_one=to_date( to_timespan('-1 month'),'Y-m');
// $last_two=to_date( to_timespan('-2 month'),'Y-m');
// $last_three=to_date( to_timespan('-3 month'),'Y-m');
//切割出年份
$tmp_year=substr($cur_month,0,4);
//切割出月份
$tmp_mon =substr($cur_month,5,2);

$tmp_forwardmonth=mktime(0,0,0,$tmp_mon-1,1,$tmp_year);
  $last_one=to_date($tmp_forwardmonth,"Y-m");
  
  $tmp_forwardmonth=mktime(0,0,0,$tmp_mon-2,1,$tmp_year);
  $last_two=to_date($tmp_forwardmonth,"Y-m");

  $tmp_forwardmonth=mktime(0,0,0,$tmp_mon-3,1,$tmp_year);
  $last_three=to_date($tmp_forwardmonth,"Y-m");
0 0
原创粉丝点击