我需要在所选月份的相应周显示一系列日期。假设选定的值是$month=2
和$year=2017
。输出应显示所选特定月份中数周的范围日期列表。
$month = $_GET['month'];
$year = $_GET['year'];
...
Output:
Week 1: 01/02/2017 - 05/02/2017
Week 2: 06/02/2017 - 12/02/2017
Week 3: 13/02/2017 - 19/02/2017
Week 4: 20/02/2017 - 26/02/2017
Week 5: 27/02/2017 - 28/02/2017
通过香港专业教育学院看当月分割到几个星期在PHP,获取星期数在一个月日期PHP?并将日期范围拆分为相应的周,但没有一个为我工作。
谢谢。
这是一种使用 strtotime 循环的方法。
我在 Unix 上加 86400*7 加一周。
$month = 2;
$year = 2017;
$week = date("W", strtotime($year . "-" . $month ."-01")); // weeknumber of first day of month
Echo date("d/m/Y", strtotime($year . "-" . $month ."-01")) ." - "; // first day of month
$unix = strtotime($year."W".$week ."+1 week");
While(date("m", $unix) == $month){ // keep looping/output of while it's correct month
Echo date("d/m/Y", $unix-86400) . "\n"; // Sunday of previous week
Echo date("d/m/Y", $unix) ." - "; // this week's monday
$unix = $unix + (86400*7);
}
Echo date("d/m/Y", strtotime("last day of ".$year . "-" . $month)); //echo last day of month
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句