php 获取星期开始与星期结束的时间戳(使用中国星期 周一 为第一天)

 

获取当前星期的开始与结束时间戳

 $data=getWeekStaAndEndTime(date("Y-m-d"));
    print_r($data);
    function getWeekStaAndEndTime($todayDate){
        $da = date("w",strtotime($todayDate));
        switch($da){
            case 0:
                $weekStart = date('Y-m-d',strtotime($todayDate.' -6 day'));
                $weekOver  = $todayDate;


                break;
            case 1:        
                $weekStart = $todayDate;
                $weekOver  = date('Y-m-d',strtotime($todayDate.' +6 day'));
                break;
            case 2:
                $weekStart = date('Y-m-d',strtotime($todayDate.' -1 day'));
                $weekOver  = date('Y-m-d',strtotime($todayDate.' +5 day'));
                break;
            case 3:
                $weekStart = date('Y-m-d',strtotime($todayDate.' -2 day'));
                $weekOver  = date('Y-m-d',strtotime($todayDate.' +4 day'));
                break;
            case 4:
                $weekStart = date('Y-m-d',strtotime($todayDate.' -3 day'));
                $weekOver  = date('Y-m-d',strtotime($todayDate.' +3 day'));
                break;
            case 5:
                $weekStart = date('Y-m-d',strtotime($todayDate.' -4 day'));
                $weekOver  = date('Y-m-d',strtotime($todayDate.' +2 day'));
                break;
            case 6:
                $weekStart = date('Y-m-d',strtotime($todayDate.' -5 day'));
                $weekOver  = date('Y-m-d',strtotime($todayDate.' +1 day'));
                break;
            default:
    }

    $weekStartTime  = strtotime($weekStart.' 0:0:0');
    $weekOverTime = strtotime($weekOver.' 23:59:59');

    $data = [
        "weekStartTime" => $weekStartTime,
        "weekOverTime" =>  $weekOverTime
    ];

    return $data;

}

 

|| 版权声明
作者:冰魄
链接:https://www.bp456.cn/79.html
声明:如无特别声明本文即为原创文章仅代表个人观点,版权归《冰魄博客》所有,欢迎转载,转载
THE END
二维码
海报
php 获取星期开始与星期结束的时间戳(使用中国星期 周一 为第一天)
  获取当前星期的开始与结束时间戳 $data=getWeekStaAndEndTime(date("Y-m-d")); print_r($data); function getWeekStaAndEndTime($todayDate……
<<上一篇
下一篇>>