zoukankan      html  css  js  c++  java
  • PHP获取本周的每一天的时间

    1.PHP获取未来一周的时间

    public function getWeek()
        {
            for($i=0;$i<7;$i++)  
            {  
                $arr[$i]=date('Y-m-d',strtotime(date('Y-m-d').'-'.$i.'day'));  
            }  
    
            return json($arr); 
        }

    2.PHP获取本周每一天的时间

    public function getDay()
        {
            $timestr = time();    //当前时间戳
            $now_day = date('w',$timestr);  //当前是周几
    
            //获取周一
            $monday_str = $timestr - ($now_day-1)*60*60*24;
            $monday = date('Y-m-d', $monday_str);
    
            //获取周日
            $sunday_str = $timestr + (7-$now_day)*60*60*24;
            $sunday = date('Y-m-d', $sunday_str);
    
            for($i=0;$i<7;$i++)  
            {  
                $arr[$i]=date('Y-m-d',strtotime($monday.'+'.$i.'day'));  
            }
            return json($arr); 
            // echo "星期一: $monday
    ";
            // echo "星期天: $sunday
    ";
        }

    效果:

    ["2018-06-11","2018-06-12","2018-06-13","2018-06-14","2018-06-15","2018-06-16","2018-06-17"]
  • 相关阅读:
    json批量设置DIV属性
    随机产生div背景颜色变化
    发送验证码倒计时
    购物网站倒计时
    ARC066B
    [Poi2011]Conspiracy
    CF1103E Radix Sum
    NOI2018 冒泡排序
    CometOJ 5E
    NOI2020 命运
  • 原文地址:https://www.cnblogs.com/zxf100/p/9184095.html
Copyright © 2011-2022 走看看