顺便了解令人困惑的 strtotime
<?php
//这样的写法会有问题,大家可以去鸟哥博客看看
//strtotime ("$firstDay + 1 month -1 day") //获取本月最后一天
/**
* 获取当天是本月的第几周
*
* @return int
* @author Henry
*/
public function getWeek(): int
{
$todayW = date('W', strtotime('now')); //获取当前周数
$eomW = date('W', strtotime('last day of')); //获取月尾周数
$weekSum = floor(date('t') / 7); //月份总天数 / 7 = 本月总周数
//本月总周数 - (本月尾周数 - 当前周数) + 1
$week = intval(($weekSum - ($eomW - $todayW)) + 1);
return $week;
}