PHP 獲取上個月1號和上個月最后一天時間戳,下個月1號和下個月最后一天的時間戳


// 上個月的時間戳
    $thismonth = date('m');
    $thisyear = date('Y');
    if ($thismonth == 1) {
        $lastmonth = 12;
        $lastyear = $thisyear - 1;
    } else {
        $lastmonth = $thismonth - 1;
        $lastyear = $thisyear;
    }

    $lastStartDay = $lastyear . '-' . $lastmonth . '-1';
    $lastEndDay = $lastyear . '-' . $lastmonth . '-' . date('t', strtotime($lastStartDay));
    $b_time = strtotime($lastStartDay);//上個月的月初時間戳
    $e_time = strtotime($lastEndDay);//上個月的月末時間戳

// 下個月的時間戳
    $thismonth = date('m');
    $thisyear = date('Y');
    if ($thismonth == 12) {
        $lastmonth = 1;
        $lastyear = $thisyear + 1;
    } else {
        $lastmonth = $thismonth + 1;
        $lastyear = $thisyear;
    }
    $lastStartDay = $lastyear . '-' . $lastmonth . '-1';
    $lastEndDay = $lastyear . '-' . $lastmonth . '-' . date('t', strtotime($lastStartDay));
    
    $b_time = strtotime($lastStartDay);//下個月的月初時間戳
    $e_time = strtotime($lastEndDay);//下個月的月末時間戳

親測有效

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM