PHP 获取 今日,昨日,上周,本月,某年时间

今日开始时间戳和结束时间戳:
$start = mktime(0,0,0,date('m'),date('d'),date('Y'));
$start = strtotime(date('Ymd'),time());
$end = mktime(0,0,0,date('m'),date('d')+1,date('Y'))-1;

昨日起始时间戳和结束时间戳:
$start = mktime(0,0,0,date('m'),date('d')-1,date('Y')); 
$end = mktime(0,0,0,date('m'),date('d'),date('Y'))-1;
$end = strtotime(date('Ymd'),time())-1;

上周起始时间戳和结束时间戳:
$start = mktime(0,0,0,date('m'),date('d')-date('w')+1-7,date('Y')); 
$end = mktime(23,59,59,date('m'),date('d')-date('w')+7-7,date('Y'));

本月起始时间戳和结束时间戳:
$start = mktime(0,0,0,date('m'),1,date('Y'));
$start = strtotime(date('Ym01'));
$end = mktime(23,59,59,date('m'),date('t'),date('Y'));
$end = strtotime(date('Ym01',strtotime('+1 month')))-1;

上月开始时间 和 结束时间
$start = date('Y-m-01 00:00:00',strtotime('-1 month'));
$end = date("Y-m-d 23:59:59", strtotime(-date('d').'day'));
$end = strtotime(date('Ym01'))-1;

上上月 开始时间 和结束时间
$start =  date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m")-2,1,date("Y")));
$start = date('Y-m-01 00:00:00',strtotime('-2 month'));
$end =  date("Y-m-d H:i:s",mktime(23,59,59,date("m")-1 ,0,date("Y")));

获取某年月的开始和结束时间
$startTime = $year.'-'.$smonth.'-1 00:00:00';
$em = $year.'-'.$emonth.'-1 23:59:59';
$endTime = date('Y-m-t H:i:s',strtotime($em));
return array('stime'=>strtotime($startTime),'etime'=>strtotime($endTime));
上一篇:Springboot整合Redis哨兵模式(Windows版本学习)


下一篇:5.1.15 MySQL 服务器时区支持