美文网首页
PHP之获取某时间段的所有日期+周几

PHP之获取某时间段的所有日期+周几

作者: Cute_小肥鸡 | 来源:发表于2020-05-12 20:46 被阅读0次

/**

* 获取指定日期段内每一天的日期

* @param Date $startdate 开始日期

* @param Date $enddate 结束日期

* @return Array

*/

public function getDateFromRange($startdate, $enddate){

    $stimestamp = strtotime($startdate);

    $etimestamp = strtotime($enddate);

    $days = ($etimestamp-$stimestamp)/86400+1;//计算日期段内有多少天

    //保存每天日期

    $weekArray = array("日","一","二","三","四","五","六");

    for($i = 0; $i < $days; $i++){

        $currentDate = date('m月d', $stimestamp+(86400*$i));

        $currentDate_1 = date('Y-m-d', $stimestamp+(86400*$i));

        $currentWeek = "周".$weekArray[date("w",strtotime($currentDate_1))];

        $date[] = ["FDate"=>$currentDate,"FWeek"=>$currentWeek];

    }

    return $date;

}

结果如下图:

相关文章

网友评论

      本文标题:PHP之获取某时间段的所有日期+周几

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