阅读

php strtotime months 错误

php  2016-05-31 20:07

如果当天为 31 号,使用 strtotime('-x months') 时的结果将不是上个月,而是当月1号。


解决方法:

<?php
    date_default_timezone_set('Asia/Shanghai');
    $timeStamp = strtotime(date('Y-m',time()) . '-01 00:00:01');
    var_dump(date('Y-m-d', strtotime(date('Y-m', strtotime('-x months', $timeStamp)))));