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;
    }
原文地址:https://www.cnblogs.com/bkhdd/p/15709759.html