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 ?>
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步