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期間,這兩個項目中哪一項仍然可行,那么它們會在一年中變現嗎?
總結
以上是生活随笔為你收集整理的php上个月的最后一天,在PHP中查找上个月的最后一天的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: oracle exp consisten
- 下一篇: 杰瑞服务器虚拟化,大家在Mac中开发PH