美文网首页
php 计算某一年某个月有几周 --- 2019-04-10

php 计算某一年某个月有几周 --- 2019-04-10

作者: 一位先生_ | 来源:发表于2019-04-10 09:27 被阅读0次

    <?php

    functionget_weekinfo($month){

        $weekinfo= array();//创建一个空数组

        $end_date= date('d',strtotime($month.' +1 month -1 day'));//计算当前月有多少天

        for($i=1; $i<$end_date; $i=$i+7) {   //循环本月有多少周

            $w= date('N',strtotime($month.'-'.$i));  //计算第一天是周几

            $weekinfo[] = array(date('Y-m-d',strtotime($month.'-'.$i.' -'.($w-1).' days')),date('Y-m-d',strtotime($month.'-'.$i.' +'.(7-$w).' days')));

        }                                                    //当周开始时间                    //结束时间

        return$weekinfo;

    }

    print_r(get_weekinfo('2017-5'));

    //执行结果

    Array

    (

        [0] => Array

            (

                [0] => 2017-05-01

                [1] => 2017-05-07

            )

        [1] => Array

            (

                [0] => 2017-05-08

                [1] => 2017-05-14

            )

        [2] => Array

            (

                [0] => 2017-05-15

                [1] => 2017-05-21

            )

        [3] => Array

            (

                [0] => 2017-05-22

                [1] => 2017-05-28

            )

        [4] => Array

            (

                [0] => 2017-05-29

                [1] => 2017-06-04

            )

    )

    ?>

    相关文章

      网友评论

          本文标题:php 计算某一年某个月有几周 --- 2019-04-10

          本文链接:https://www.haomeiwen.com/subject/hrmgiqtx.html