php的strtotime(’+1 month’)函数,如果今天是1月31号,使用strtotime(’+1 month’)函数变成3月3号,而我的结果是想获得2月份最后一天的日期,也就是2月28号,下面这段代码可以解决这个bug
if(date("d",strtotime("+1 month"))!=date("d")){
//下个月总天数
$lastDay = cal_days_in_month(CAL_GREGORIAN,date("m",strtotime("+1 month"))-1,date("Y",strtotime("+1 month")));
//年份
$y=date("Y",strtotime("+1 month"));
//strtotime计算的月份-1
$m= date("m",strtotime("+1 month"))-1<10 ? "0".(date("m",strtotime("+1 month"))-1) : date("m",strtotime("+1 month"))-1;
echo $y."-".$m."-".$lastDay."</br>";
}else{
echo date("Y-m-d",strtotime("+1 month"))."</br>";
}