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);

$lastDateOfPreviousMonth = $lastYear . '-' . $lastMonth . '-' . $lastDayOfMonth;

$newLastDateOfMonth = date('F j, Y', strtotime($lastDateOfPreviousMonth));

?>

$lastDateOfPreviousMonth正如预期返回2012-09-30;然而,在尝试将其转换为2012年9月30日之后 – $newLastDateOfMonth将于2012年10月1日返回.我似乎在哪里出错?

编辑:如果使用日期(“t / m / Y”,strtotime(“上个月”));或日期(‘Y-m-d’,strtotime(“上个月的最后一天”));在2013-01-01期间,这两个项目中哪一项仍然可行,那么它们会在一年中变现吗?


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部