我有一系列随机日期(不是来自MySQL).我需要将它们按周分组为第1周,第2周,依此类推至第5周.
我有的是这个:
$dates = array('2015-09-01','2015-09-05','2015-09-06','2015-09-15','2015-09-17');
Run Code Online (Sandbox Code Playgroud)
我需要的是通过提供日期来获取月份周数的函数.
我知道我可以通过这样做获得
date('W',strtotime('2015-09-01'));
周数,但本周数是年(1-52)之间的数字,但我只需要一个月的周数,例如2015年9月有5周:
我应该能够通过提供日期来获得第一周的第1周
$weekNumber = getWeekNumber('2015-09-01') //output 1;
$weekNumber = getWeekNumber('2015-09-17') //output 3;
Run Code Online (Sandbox Code Playgroud) 指定日期时:
datetime.datetime(2011, 8, 15)
Run Code Online (Sandbox Code Playgroud)
我如何才能知道这是本月的第三周?
如果我想要这个约会怎么办?
datetime.datetime(2011, 2, 28) //should return 4
datetime.datetime(2011, 8, 29) //should return 5
Run Code Online (Sandbox Code Playgroud)
据我所知,如果给定日期是闰年,只有2月有4周(bissextile)
嗨朋友,我需要得到一周的计数.
根据当前年份的前1,2,3 .... 52.
在php周默认从星期一或星期日开始
无论如何设置'星期二'有默认的开始日.
我的代码是......
echo "current week of 2012 this year is ..". $weekNumber = date("W");
Run Code Online (Sandbox Code Playgroud)
输出为exapmle 16.而正确的应该是15.
因为我需要从星期二而不是星期一开始的一周,任何人都可以告诉我该怎么做.
因为如果找到答案的话,关于它的文档很少,将来会帮助其他人:)
你的帮助和时间将不胜感激.或者请在评论中建议我然后:)
我目前正在生成一个 html 表,其中包含标题中的日期
这些日期据称是全年每周的第一天(显示的年份可能会根据过滤器发生变化),它们是由以下代码生成的
<?php $firstDay = strtotime($year . 'W' . str_pad($week, 2, '0', STR_PAD_LEFT)); ?>
<td><?= date('d/m/Y', $firstDay) ?></td>
Run Code Online (Sandbox Code Playgroud)
这是一个for循环,它使$week从 变为1全年的周数。
我注意到,有些年来,前一年 12 月的最后一个星期一也包含在其中,例如29/12/2014当我2015在过滤器中选择时。
到目前为止,为了确定一个月中的周数,我曾经以编程方式计算该月中星期一的数量,并将其用作日期行上方行的 colspan,因此,一月有无数周多年来,这使得桌子发生了变化。
今年渲染的 html2015看起来像这样
<table>
<thead>
<tr>
<th colspan="4">January</th>
<th colspan="4">February</th>
[...]
</tr>
<tr>
<!-- Under January cell -->
<th>29/12/2014</th>
<th>05/01/2015</th>
<th>12/01/2015</th>
<th>19/01/2015</th>
<!-- Under February cell -->
<th>26/01/2015</th>
<th>02/02/2015</th>
[...]
</tr>
</thead>
[...]
Run Code Online (Sandbox Code Playgroud)
在搜索和测试了很多周每月计数器之后,我发现的这些计数器似乎都不包括上一年的上周一。
谁能找出如何计算周数,包括上一年发生的额外一周?