在包含的脚本中
date('Y-m-d', strtotime('first day of last month'))
Run Code Online (Sandbox Code Playgroud)
在版本5.3.10(localhost)中,我得到了例如'2012-03-01'.
在版本5.2.17(远程主机)中我得到'1969-12-31'.
是否有表达式会返回两个版本的预期结果(例如,'2012-03-01')?
你应该使用mktime()函数:
<?php
echo date('Y-m-d', mktime(0,0,0,date('n')-1,1,date('Y'))); //2012-03-01
?>
Run Code Online (Sandbox Code Playgroud)
date('Y-m-d', strtotime('first day of -1 month'))
Run Code Online (Sandbox Code Playgroud)
在 PHP 7.0 上运行良好