php 获取今日、昨日、上周、本月的起始时间戳和结束时间戳的方法
//获取特定的时间段
protected function settime($time){
//筛选时间戳最大值, 最小值
$maxstamp = null;
$mixstamp = null;
switch ($time) {
case 'today':{
$maxstamp=mktime(0,0,0,date('m'),date('d'),date('Y'));
$mixstamp=mktime(0,0,0,date('m'),date('d')+1,date('Y'))-1;
}
break;
case '48h':{
$maxstamp=mktime(0,0,0,date('m'),date('d'),date('Y'));
$mixstamp=mktime(0,0,0,date('m'),date('d'),date('Y'))-1;
}
break;
case 'yesterday':{
$maxstamp=mktime(0,0,0,date('m'),date('d')-1,date('Y'));
$mixstamp=mktime(0,0,0,date('m'),date('d'),date('Y'))-1;
}
break;
case 'week':
{
$maxstamp=mktime(0,0,0,date('m'),date('d')-date('w')+1-7,date('Y'));
$mixstamp=mktime(23,59,59,date('m'),date('d')-date('w')+7-7,date('Y'));
}
break;
case 'month':{
$maxstamp=mktime(0,0,0,date('m'),1,date('Y'));
$mixstamp=mktime(23,59,59,date('m'),date('t'),date('Y'));
}
break;
default:{
$maxstamp=mktime(0,0,0,date('m'),date('d'),date('Y'));
$mixstamp=mktime(0,0,0,date('m'),date('d')+1,date('Y'))-1;
}
break;
}
$timestamp = array(
'maxstamp'=>$maxstamp,
'mixstamp'=>$mixstamp
);
return $timestamp;
}