[php_13]PHP获取指定月份的月初月尾时间

来源:互联网 发布:ol3vs数据库app 编辑:程序博客网 时间:2024/05/16 15:02

原文地址:http://blog.sina.com.cn/s/blog_813e149b01010qk5.html


PHP获取指定月份的月初月尾时间

获取上月月初月尾时间:

$startday=strtotime(date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m")-1,1,date("Y"))));//获取上月头时间
$endday = strtotime(date("Y-m-d H:i:s",mktime(23,59,59,date("m") ,0,date("Y")))); //获取上月尾时间

 

获取指定月份月初月尾时间:

$yourdate = strtotime(date("Y-m-01 00:00:00"));

$endday = strtotime(date('Y-m-d', mktime(23, 59, 59, date('m', strtotime($yourdate))+1, 00)));

 

获取本月月初月尾时间:

date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m"),1,date("Y")));
date("Y-m-d H:i:s",mktime(23,59,59,date("m"),date("t"),date("Y")));


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

阅读全文
0 0