PHP获取指定的时间戳

  1. PHP获取指定月份的时间戳
$Y = 2016;//获取年,示例,真实环境从前端获取数据  
$m = 8;//获取月,示例,真实环境从前端获取数据  
$month = $Y."-".$m;//当前年月  
$month_start = strtotime($month);//指定月份月初时间戳  
$month_end = mktime(23, 59, 59, date('m', strtotime($month))+1, 00);//指定月份月末时间戳

        2.获取指定时间戳

  //PHP获取今天内的时间 今天开始和结束的时间戳

$t = time();
$start = mktime(0,0,0,date("m",$t),date("d",$t),date("Y",$t));
$end = mktime(23,59,59,date("m",$t),date("d",$t),date("Y",$t));



$date
= strtotime('-6 days');//6天前的"当前"时间戳 $begin=mktime(0,0,0,date('m'),date('d')-6,date('Y'));//6天前的起始0点时间戳

 

 

        3.获取指定时间(格式:2017-11-16 0:0:0)

echo date("Y-m-d 0:0:0",strtotime("-1 week"));//7天前起始0点时间 2017-11-16 0:0:0
echo date("Y-m-d 00:00:00",strtotime("-2 day"));//2017-11-29 00:00:00

 

posted @ 2017-07-06 19:13  MeetU  阅读(3245)  评论(0编辑  收藏  举报