phpstrtotime()对于31日求上个月有问题

PHP自带的strtotime()对于31日求上个月有问题,如下:

<?php  
$date = "2012-07-31";  
$date_unix = strtotime($date);  
$lastmonth = strtotime("last month",$date_unix);//或者strtotime("-1 month",$date_unix);  
echo date("Y-m-d H:i:s",$lastmonth)."<br />";//输出:2012-07-01 00:00:00  
$last_month_end = strtotime(date("Ym"."01000000",$date_unix)) - 1;//上个月的最后一秒  
echo date("Y-m-d H:i:s",$last_month_end);//输出:2012-06-30 23:59:59  
?> 

 

posted on 2016-03-10 17:24  手撕高达的村长  阅读(336)  评论(0编辑  收藏  举报

导航