• PHP获取一周的日期


    function get_week($time = '', $format='Y-m-d'){
            $time = $time != '' ? $time : time();
            //获取当前周几
            $week = date('w', $time);
            $weekname = array('周一','周二','周三','周四','周五','周六','周日');
            //星期日排到末位
            if(empty($week)){
                $week=7;
            }
            $date = [];
            for ($i=0; $i<7; $i++){
                $date_time = date($format ,strtotime( '+' . $i+1-$week .' days', $time));
                $date[$i]['date'] = $date_time;
                $date[$i]['time'] = strtotime($date_time);
                $date[$i]['week'] = $weekname[$i];
            }
            return $date;
        }

    打印结果

    Array
    (
        [0] => Array
            (
                [date] => 2019-06-17
                [time] => 1560700800
                [week] => 周一
            )
    
        [1] => Array
            (
                [date] => 2019-06-18
                [time] => 1560787200
                [week] => 周二
            )
    
        [2] => Array
            (
                [date] => 2019-06-19
                [time] => 1560873600
                [week] => 周三
            )
    
        [3] => Array
            (
                [date] => 2019-06-20
                [time] => 1560960000
                [week] => 周四
            )
    
        [4] => Array
            (
                [date] => 2019-06-21
                [time] => 1561046400
                [week] => 周五
            )
    
        [5] => Array
            (
                [date] => 2019-06-22
                [time] => 1561132800
                [week] => 周六
            )
    
        [6] => Array
            (
                [date] => 2019-06-23
                [time] => 1561219200
                [week] => 周日
            )
    
    )
  • 相关阅读:
    Expect学习笔记(1)
    Awk 实例,第 3 部分
    ELF文件格式(中文版)
    sed 实例,第 1 部分
    Expect 教程中文版
    csc工具一般使用说明zz
    Microsoft Office Word 2010(zz)
    记录XPO查询 日志
    C#中判断文件或文件夹是否存在
    Discuz数据库结构1
  • 原文地址:https://www.cnblogs.com/bluealine/p/11044602.html
Copyright © 2020-2023  润新知