PHP 获取本周所有日期,PHP 获取当前时间所在周七天具体日期方法:
/** * 获取本周所有日期 */ function get_week($time = '', $format='Y-m-d'){ $time = $time != '' ? $time : time(); $week = date('w', $time); $date = []; for ($i=1; $i<=7; $i++){ $date[$i] = date($format ,strtotime( '+' . $i-$week .' days', $time)); } return $date; }
调用及输出:
print_r(get_week()); Array ( [1] => 2018-11-19 [2] => 2018-11-20 [3] => 2018-11-21 [4] => 2018-11-22 [5] => 2018-11-23 [6] => 2018-11-24 [7] => 2018-11-25 )
声明:本文为原创文章,版权归主机之家测评所有,欢迎分享本文,转载请保留出处!