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-06-18 [2] => 2018-06-19 [3] => 2018-06-20 [4] => 2018-06-21 [5] => 2018-06-22 [6] => 2018-06-23 [7] => 2018-06-24 )
获取最近七天日期:
/** * 获取最近七天所有日期 */ function 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; }
执行结果:
print_r(get_weeks()); Array ( [1] => 2018-06-13 [2] => 2018-06-14 [3] => 2018-06-15 [4] => 2018-06-16 [5] => 2018-06-17 [6] => 2018-06-18 [7] => 2018-06-19 )
总结
相关推荐
zyyjay 2020-11-09
xuebingnan 2020-11-05
samtrue 2020-11-22
stefan0 2020-11-22
yifangs 2020-10-13
songshijiazuaa 2020-09-24
hebiwtc 2020-09-18
天步 2020-09-17
83911535 2020-11-13
whatsyourname 2020-11-13
zhouyuqi 2020-11-10
Noneyes 2020-11-10
mathchao 2020-10-28
王志龙 2020-10-28
wwwsurfphpseocom 2020-10-28
diskingchuan 2020-10-23
savorTheFlavor 2020-10-23