时间戳格式

//获取今日开始时间戳和结束时间戳  
$beginToday = mktime(0,0,0,date('m'),date('d'),date('Y'));  
$endToday = mktime(0,0,0,date('m'),date('d')+1,date('Y'))-1;  
 
//获取昨日起始时间戳和结束时间戳  
$beginYesterday = mktime(0,0,0,date('m'),date('d')-1,date('Y'));  
$endYesterday = mktime(0,0,0,date('m'),date('d'),date('Y'))-1;  
 
//获取本周起始时间戳和结束时间戳   
$beginThisweek = mktime(0,0,0,date('m'),date('d')-date('w')+1,date('y'));  
$endThisweek = mktime(23,59,59,date("m"),date("d")-date("w")+7,date("Y"));  
 
//获取上周起始时间戳和结束时间戳  
$beginLastweek = mktime(0,0,0,date('m'),date('d')-date('w')+1-7,date('Y'));  
$endLastweek = mktime(23,59,59,date('m'),date('d')-date('w')+7-7,date('Y'));  
 
//获取本月起始时间戳和结束时间戳  
$beginThismonth = mktime(0,0,0,date('m'),1,date('Y'));  
$endThismonth = mktime(23,59,59,date('m'),date('t'),date('Y'));  
 
 //上个月的起始时间:  
$begin_time = strtotime(date('Y-m-01 00:00:00',strtotime('-1 month')));  
$end_time = strtotime(date("Y-m-d 23:59:59", strtotime(-date('d').'day')));  
 
$begin_year = strtotime(date("Y",time())."-1"."-1"); //本年开始  
$end_year = strtotime(date("Y",time())."-12"."-31"); //本年结束  
 
//现在的时间到第二天凌晨相差的时间戳  
$time = (strtotime(date('Y-m-d'))+3600*24) - time() ;

$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";

 

日期格式

//上周起始时间
echo date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m"),date("d")-date("w")+1-7,date("Y")));
echo date("Y-m-d H:i:s",mktime(23,59,59,date("m"),date("d")-date("w")+7-7,date("Y")));

//本周起始时间
echo date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m"),date("d")-date("w")+1,date("Y")));
echo date("Y-m-d H:i:s",mktime(23,59,59,date("m"),date("d")-date("w")+7,date("Y")));

//上月起始时间
echo date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m")-1,1,date("Y")));
echo date("Y-m-d H:i:s",mktime(23,59,59,date("m") ,0,date("Y")));

//本月起始时间
echo date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m"),1,date("Y")));
echo date("Y-m-d H:i:s",mktime(23,59,59,date("m"),date("t"),date("Y")));

//本年起始时间
echo date(‘Y-01-01’); 
echo date(‘Y-12-31’);

 

 

文章摘自:https://www.cnblogs.com/houss/p/12001270.html

 posted on 2020-06-30 11:51  三哥-Noble  阅读(152)  评论(0编辑  收藏  举报
TOP