时间点
//当前时间 echo date("Y-m-d H:i:s",time()); //明天此时时间 echo date("Y-m-d H:i:s",strtotime("+1 day")); //指定时间 echo date("Y-m-d H:i:s",strtotime("-1 day")); //下星期时间 echo date("Y-m-d H:i:s",strtotime("+1 week")) //上个星期此时时间 echo date("Y-m-d H:i:s",strtotime("-1 week")); //下星期几时间 echo date("Y-m-d H:i:s",strtotime("next Thursday")); //指定时间 echo date("Y-m-d H:i:s",strtotime("last Thursday"));
时间段:
今天
$startDate = mktime(0,0,0,date("m"),date("d"),date("Y")); $endDate = mktime(0,0,0,date('m'),date('d')+1,date('Y'))-1;
昨天
$startDate = mktime(0,0,0,date("m"),date("d")-1,date("Y")); $endDate = mktime(0,0,0,date("m"),date("d"),date("Y"))-1;
明天
$startDate = mktime(0,0,0,date("m"),date("d")+1,date("Y")); $endDate = mktime(0,0,0,date("m"),date("d")+2,date("Y"))-1;
本周
$w = date("w"); $startDate = mktime(0,0,0,date("m"),date("d")-$w+1,date("Y")); $endDate=mktime(23,59,59,date('m'),date('d')-date('w')+7,date('Y'));
上周
$startDate=mktime(0,0,0,date('m'),date('d')-date('w')+1-7,date('Y')); $endDate=mktime(23,59,59,date('m'),date('d')-date('w')+7-7,date('Y'));
下周
$startDate=mktime(0,0,0,date('m'),date('d')-date('w')+7+1,date('Y')); $endDate=mktime(23,59,59,date('m'),date('d')-date('w')+7+7,date('Y'));
本月
$startDate = mktime(0,0,0,date("m"),1,date("Y")); $endDate = mktime(23,59,59,date('m'),date('t'),date('Y'))-1;
上月
$startDate = mktime(0,0,0,date("m")-1,1,date("Y"));
$endDate = mktime(0,0,0,date("m"),1,date("Y"))-1;
//下月
$startDate = mktime(0,0,0,date("m")+1,1,date("Y"));
$endDate = mktime(0,0,0,date("m")+2,1,date("Y"))-1;
本季度
$getMonthDays = date("t",mktime(0, 0 , 0,date('n')+(date('n')-1)%3,1,date("Y")));//本季度未最后一月天数 echo '<br>本季度:<br>'; echo date('Y-m-d H:i:s', mktime(0, 0, 0,date('n')-(date('n')-1)%3,1,date('Y'))),"\n"; echo date('Y-m-d H:i:s', mktime(23,59,59,date('n')+(date('n')-1)%3,$getMonthDays,date('Y'))),"\n"; $season = ceil((date('n'))/3);//当月是第几季度 echo '<br>本季度起始时间:<br>'; echo date('Y-m-d H:i:s', mktime(0, 0, 0,$season*3-3+1,1,date('Y'))),"\n"; echo date('Y-m-d H:i:s', mktime(23,59,59,$season*3,date('t',mktime(0, 0 , 0,$season*3,1,date("Y"))),date('Y'))),"\n"; $season = ceil((date('n'))/3)-1;//上季度是第几季度 echo '<br>上季度起始时间:<br>'; echo date('Y-m-d H:i:s', mktime(0, 0, 0,$season*3-3+1,1,date('Y'))),"\n"; echo date('Y-m-d H:i:s', mktime(23,59,59,$season*3,date('t',mktime(0, 0 , 0,$season*3,1,date("Y"))),date('Y'))),"\n";
今年
$startDate = mktime(0,0,0,1,1,date("Y")); $endDate = mktime(0,0,0,1,1,date("Y")+1)-1;
结果如:
1483200000 1514735999
格式化:
2017-01-01 00:00:00 2017-12-31 23:59:59