php 取出周一和周日的时间戳

作者:袖梨 2022-06-24
 代码如下 复制代码

function getmonsun(){
    $curtime=time();
     
    $curweekday = date('w');

     //为0是 就是 星期七
    $curweekday = $curweekday?$curweekday:7;


    $curmon = $curtime - ($curweekday-1)*86400;
    $cursun = $curtime + (7 - $curweekday)*86400;
    
    $cur['mon'] = $curmon;
    $cur['sun'] = $cursun;

    return $cur;
}
    $cur = getmonsun();

    echo date('y-m-d',$cur['mon']);
    echo " ";
    echo date('y-m-d',$cur['sun']);

 
//方法二 利用php strtotime函数

 代码如下 复制代码
 echo strtotime('last monday');
 echo '
';
 echo strtotime('next sunday');

 

相关文章

精彩推荐