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