一年的碳清单
我每年都有回报周的功能:
function getWeek(){
$today = \Carbon\Carbon::today();
$date = $today->copy()->firstOfYear()->startOfDay();
$eom = $today->copy()->endOfYear()->startOfDay();
$dates = [];
for($i = 1; $date->lte($eom); $i++){
$startDate = $date->copy();
while($date->dayOfWeek != \Carbon\Carbon::SUNDAY && $date->lte($eom)){
$date->addDay();
}
$dates['w'.$i] = $startDate->format('d/m/Y') . ' - ' . $date->format('d/m/Y');
$date->addDay();
}
return $dates;
}
功能在2022年的功能返回53周,但在2022年为52周。这是返回$ dates
如何更改功能以返回第一个位置以返回一周的完整日期(27/12/2021-02/02/01/2022 ),在年份的最后一个位置相同
I have function of return weeks in year:
function getWeek(){
$today = \Carbon\Carbon::today();
$date = $today->copy()->firstOfYear()->startOfDay();
$eom = $today->copy()->endOfYear()->startOfDay();
$dates = [];
for($i = 1; $date->lte($eom); $i++){
$startDate = $date->copy();
while($date->dayOfWeek != \Carbon\Carbon::SUNDAY && $date->lte($eom)){
$date->addDay();
}
$dates['w'.$i] = $startDate->format('d/m/Y') . ' - ' . $date->format('d/m/Y');
$date->addDay();
}
return $dates;
}
And the function return 53 weeks in year 2022 but in 2022 is 52 weeks. This is a result of return $dates
How to change the function to return first position to return full dates of week (27/12/2021 - 02/01/2022) and the same at the last position in year
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
该解决方案总是显示完整的几周。使用ISO 8601周数。
只需要日期时间。添加了钥匙的一年,以使它们始终是独一无二的。
由于不需要碳,因此您还可以对其进行测试在这里。
This solution always shows the complete weeks. Uses the ISO 8601 week number.
Only DateTime is required. The year was added for the key so that they are always unique.
Since carbon is not required, you can also test it here.
我认为你是错误的。
I think you are mistaken.