php 获取指定日期内每天的开始和结束时间


/**
     *获取指定一段时间内的每天的开始时间
     * @param $startdate 开始日期 时间戳
     * @param $enddate 结束日期 时间戳
     * @param $format 时间格式 0:时间戳 1日期格式
     * @return array 返回一维数组
     */
    public static function PeriodTime($stimestamp, $etimestamp, $format=0) {
        $days = floor(($etimestamp-$stimestamp)/86400+1);    // 保存每天日期
        $date = array();
        if ($days == 1) {
            //一天内
            $date[0]['start'] = $stimestamp;
            $date[0]['end'] = $etimestamp;
        }else{
            for($i=0; $i<$days; $i++){
                if ($format==0) {
                    $date[$i]['start'] = $stimestamp+(86400*$i);
                    $date[$i]['end'] = strtotime(date('Y-m-d 23:59:59', $date[$i]['start']));
                }else{
                    $date[$i]['start'] = date('Y-m-d 00:00:00', $stimestamp+(86400*$i));
                    $date[$i]['end'] = date('Y-m-d 23:59:59', $stimestamp+(86400*$i));
                }
            }
        }
        //结果
        return $date;
    }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM