【精簡(jiǎn)】PHP 獲取本月第一天、最后一天,本周第一天、最后一天時(shí)間戳

大家在做開(kāi)發(fā)時(shí)經(jīng)常需要統(tǒng)計(jì)本月、本周的數(shù)據(jù),如何獲取獲取正確獲取時(shí)間戳范圍非常關(guān)鍵,廢話不多說(shuō),直接上代碼!
我本地時(shí)間為 2019年8月14日

獲取本月端點(diǎn)時(shí)間戳
function getCurrMonthEndpointTime(){
    $start=strtotime(date('Y-m'));
    $end=strtotime(date('Y-m',strtotime('+1 month')))-1;
    return [$start,$end];
}

//結(jié)果:
Array
(
    [0] => 1564588800  //2019-08-01 00:00:00
    [1] => 1567267199 // 2019-08-31 23:59:59
)
獲取本周端點(diǎn)時(shí)間戳
function getCurrWeekEndpointTime(){
    $startDate = date('Y-m-d',strtotime('this week'));//2021-06-21
        $endDate = date('Y-m-d',strtotime('next week'));//2021-06-28
        $start = strtotime($startDate);
        $end = strtotime($endDate);
        return [$start,$end];
}
//結(jié)果:
Array
(
    [0] => 1624204800 //2021-06-21 00:00:00
    [1] => 1624809600 //2021-06-28 00:00:00
)

建議使用方式:

list($start,$end)=getCurrMonthEndpointTime();
list($start,$end)=getCurrWeekEndpointTime();
嗯~現(xiàn)在拿到了start和end 時(shí)間戳,你可為所欲為了~?。?!
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容