本文操作环境:windows7系统、PHP7.1版、Dell G3电脑。php怎么计算一个月有几周?php 计算某一年某个月有几周代码如下:<?php function get_weekinfo($month){ $weeki
本文操作环境:windows7系统、PHP7.1版、Dell G3电脑。
php怎么计算一个月有几周?
php 计算某一年某个月有几周
代码如下:
<?php
function get_weekinfo($month){
$weekinfo = array();//创建一个空数组
$end_date = date('d',strtotime($month.' +1 month -1 day'));//计算当前月有多少天
for ($i=1; $i <$end_date ; $i=$i+7) { //循环本月有多少周
$w = date('N',strtotime($month.'-'.$i)); //计算第一天是周几
$weekinfo[] = array(date('Y-m-d',strtotime($month.'-'.$i.' -'.($w-1).' days')),date('Y-m-d',strtotime($month.'-'.$i.' +'.(7-$w).' days')));
} //当周开始时间 //结束时间
return $weekinfo;
}
print_r(get_weekinfo('2017-5'));
执行结果
Array
(
[0] => Array
(
[0] => 2017-05-01
[1] => 2017-05-07
)
[1] => Array
(
[0] => 2017-05-08
[1] => 2017-05-14
)
[2] => Array
(
[0] => 2017-05-15
[1] => 2017-05-21
)
[3] => Array
(
[0] => 2017-05-22
[1] => 2017-05-28
)
[4] => Array
(
[0] => 2017-05-29
[1] => 2017-06-04
)
)
?>
--结束END--
本文标题: php怎么计算一个月有几周
本文链接: https://www.lsjlt.com/news/144.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2023-09-28
2023-09-28
2023-09-28
2023-09-28
2023-09-28
2023-09-28
2023-09-28
2023-09-28
2023-09-28
2023-09-27
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0