以前用strtotime进行处理,现在手册上不推荐这个方法了。
使用DateTime处理,如下:
//日期加一年 $tmpSqlStartDate=new DateTime($startData); $tmpSqlStartDate->sub(new DateInterval('P1Y')); $sqlStartDate=$tmpSqlStartDate->format('Y-m'); //日期减一年 $data=new DateTime($current); $data->sub(new DateInterval('P1Y')); //单位支持: y 多少年。 m 多少月。 d 多少天。 h 多少小时。 i 多少分钟。 s 多少秒。 f 多少微秒。