脚本宝典收集整理的这篇文章主要介绍了在PHP中查找上个月的最后一天,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
<?PHP $currentMonth = date('n'); $currentYear = date('Y'); if($currentMonth == 1) { $lastMonth = 12; $lastYear = $currentYear - 1; } else { $lastMonth = $currentMonth -1; $lastYear = $currentYear; } if($lastMonth < 10) { $lastMonth = '0' . $lastMonth; } $lastDayOfMonth = date('t',$lastMonth); $lastDateOfPrev@R_502_2469@sMonth = $lastYear . '-' . $lastMonth . '-' . $lastDayOfMonth; $newLastDateOfMonth = date('F j,Y',strtotime($lastDateOfPRev@R_502_2469@sMonth)); ?>
$lastDateOfPrev@R_502_2469@sMonth正如预期返回2012-09-30;然而,在尝试将其转换为2012年9月30日之后 – $newLastDateOfMonth将于2012年10月1日返回.我似乎在哪里出错?
编辑:如果使用日期(“t / m / Y”,strtotime(“上个月”));或日期(‘Y-m-d’,strtotime(“上个月的最后一天”));在2013-01-01期间,这两个项目中哪一项仍然可行,那么它们会在一年中变现吗?
echo date('Y-m-d',strtotime('last day of prev@R_502_2469@s month')); //2012-09-30
要么
$date = new DateTime(); $date->modify("last day of prev@R_502_2469@s month"); echo $date->format("Y-m-d");
后来编辑:php.net documentation – relative formats for strtotime(),DateTime and date_create()
以上是脚本宝典为你收集整理的在PHP中查找上个月的最后一天全部内容,希望文章能够帮你解决在PHP中查找上个月的最后一天所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。