PHP手册里面有现成的函数可以调用,不用自己写: $lastmonthday = strtotime("-1 month", time()); echo "上个月最后一天是".date("Y-m-t", $lastmonthday);