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"]
  • 相关阅读:
    css列表
    css字体
    css文本
    css背景
    css里的属性
    MySQL语法大全_自己整理的学习笔记
    必看的 jQuery性能优化的38个建议
    p​h​p​异​常​机​制
    常用软件
    php过滤危险html代码
  • 原文地址:https://www.cnblogs.com/zxf100/p/9184095.html
Copyright © 2011-2022 走看看