1. 程式人生 > 其它 >php 獲取指定日期內每天的開始和結束時間

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; }