大家在做開發(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();