php自动获取上一个月的起始时间


1、借鉴评论的方法[20170309 edit]

function get_month_start_end($timestamp)
{
    !empty($timestamp) OR $timestamp = time();

    $last_month = date('Y-m-01', $timestamp);
    $last['first'] = strtotime($last_month);
    $last['end'] = strtotime("$last_month +1 month -1 seconds");

    return $last;
}

2、old方法

$last_month = date('Y-m', strtotime('last month'));

$last['first'] = $last_month . '-01 00:00:00';
$last['end'] = date(‘Y-m-d H:i:s’, strtotime("$last_month +1 month -1 day +23 hours +59 minutes +59 seconds"));


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM