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 @ 2015-08-31 08:18  quixon  阅读(294)  评论(0编辑  收藏  举报