线上服务咨询
php 获取上周,本周,上月,本月,N月前后时间戳
发表时间:2024-03-14 11:22:15
作者:小Q
浏览次数:4880
// 本周
$btime = strtotime('this week Monday');// 获取本周一的时间戳
$etime = $btime+86400*7-1;
// 上周
$btime = strtotime('-1 week Monday',$btime); // 获取上周一的时间戳
$etime = $btime+86400*7-1;
//本月
$btime = strtotime(date('Y-m')); //获取本月第一天的时间戳
$etime = strtotime("+1 month", $btime) - 1; // 获取本月最后一天的时间戳
//N月前时间戳
$n = 1; //上月
$time = strtotime('-'.$n.' month', time()); //上月时间戳
$betime= strtotime(date('Y-m-01', $time)); //上月1号时间戳
$t = date('t',$time); //这个月有多少天
$etime = $betime+86400*($t+1)-1