获取一周,一月的所有日期方法
获取一周
$get_week = function ($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; };
获取一月
$get_month = function ($time = '', $format='Y-m-d'){ $time = $time != '' ? $time : time(); // 获取天 $day = (int)date('d', $time); // 获取月份有多少天 $t = date('t', $time); $date = []; for ($i=1; $i<=$t; $i++){ dump('+' . $i-$day .' days'); $date[$i] = date($format ,strtotime( '+' . $i-$day .' days', $time)); } return $date; };
获取近七天
$get_near_day = get_weeks($time = '', $format='Y-m-d'){ $time = $time != '' ? $time : time(); $date = []; for ($i=1; $i<=7; $i++){ $date[$i] = date($format ,strtotime( '+' . $i-7 .' days', $time)); } return $date; };