// 上个月的时间戳 $thismonth = date('m'); $thisyear = date('Y'); if ($thismonth == 1) { $lastmonth = 12; $lastyear = $thisyear - 1; } else { $lastmonth = $thismonth - 1; $lastyear = $thisyear; } $lastStartDay = $lastyear . '-' . $lastmonth . '-1'; $lastEndDay = $lastyear . '-' . $lastmonth . '-' . date('t', strtotime($lastStartDay)); $b_time = strtotime($lastStartDay);//上个月的月初时间戳 $e_time = strtotime($lastEndDay);//上个月的月末时间戳 // 下个月的时间戳 $thismonth = date('m'); $thisyear = date('Y'); if ($thismonth == 12) { $lastmonth = 1; $lastyear = $thisyear + 1; } else { $lastmonth = $thismonth + 1; $lastyear = $thisyear; } $lastStartDay = $lastyear . '-' . $lastmonth . '-1'; $lastEndDay = $lastyear . '-' . $lastmonth . '-' . date('t', strtotime($lastStartDay)); $b_time = strtotime($lastStartDay);//下个月的月初时间戳 $e_time = strtotime($lastEndDay);//下个月的月末时间戳
亲测有效
本文详细介绍了如何使用PHP编程语言来获取指定月份的开始和结束时间戳,具体包括上个月和下个月的月初及月末日期。通过判断当前月份,动态调整年份和月份,实现跨年的日期计算,适用于需要按月统计或处理数据的场景。

1829

被折叠的 条评论
为什么被折叠?



