Php 如何在不包括周末的两次约会之间以分钟为单位获得差异

Php 如何在不包括周末的两次约会之间以分钟为单位获得差异,php,php-carbon,Php,Php Carbon,如何在两次约会之间以分钟为单位进行区分,但周末除外(周六和周日) 当达到最大循环次数(NEXT_MAX_尝试次数=1000次)时,实际上会发生这种情况,这是由于周末的分钟数造成的 虽然您的方法在理论上是正确的,但这将是一种放慢速度并在每分钟内重复几天的方法 你可以在一天的基础上计算,直到一天结束,如果不是周末,加上diffInMinutes,然后在第二天再做一次 use Carbon\CarbonImmutable; $created = CarbonImmutable::parse(&quo

如何在两次约会之间以分钟为单位进行区分,但周末除外(周六和周日)


当达到最大循环次数(
NEXT_MAX_尝试次数=1000次)时,实际上会发生这种情况,这是由于周末的分钟数造成的

虽然您的方法在理论上是正确的,但这将是一种放慢速度并在每分钟内重复几天的方法

你可以在一天的基础上计算,直到一天结束,如果不是周末,加上diffInMinutes,然后在第二天再做一次

use Carbon\CarbonImmutable;

$created = CarbonImmutable::parse("2021-04-11 00:07:13");
$firstResponse = CarbonImmutable::parse("2021-04-12 12:35:04");
$diffInMinutes = 0;
$step = $created;

while ($step < $firstResponse) {
    if ($step->isWeekend()) {
        $step = $step->next('Monday');

        continue;
    }

    $nextStep = min($firstResponse, $step->addDay()->startOfDay());

    $diffInMinutes += $step->diffInMinutes($nextStep);
    $step = $nextStep;
}

echo $diffInMinutes;
使用碳\CarbonImmutable;
$created=CarbonImmutable::parse(“2021-04-11 00:07:13”);
$firstResponse=CarbonImmutable::parse(“2021-04-12 12:35:04”);
$diffInMinutes=0;
$step=$created;
while($step<$firstResponse){
如果($step->isWeekend()){
$step=$step->next(“星期一”);
继续;
}
$nextStep=min($firstResponse,$step->addDay()->startOfDay());
$diffInMinutes+=$step->diffInMinutes($nextStep);
$step=$nextStep;
}
回声$diffin分钟;

注意:警告,如果使用
Carbon
而不是
CarbonImmutable
您将需要替换
$step=$created$step=$created->toImmutable()进行编码>

当达到最大循环次数(
NEXT\u MAX\u尝试次数=1000次)时,实际上会发生这种情况,这是由于周末的分钟数造成的

虽然您的方法在理论上是正确的,但这将是一种放慢速度并在每分钟内重复几天的方法

你可以在一天的基础上计算,直到一天结束,如果不是周末,加上diffInMinutes,然后在第二天再做一次

use Carbon\CarbonImmutable;

$created = CarbonImmutable::parse("2021-04-11 00:07:13");
$firstResponse = CarbonImmutable::parse("2021-04-12 12:35:04");
$diffInMinutes = 0;
$step = $created;

while ($step < $firstResponse) {
    if ($step->isWeekend()) {
        $step = $step->next('Monday');

        continue;
    }

    $nextStep = min($firstResponse, $step->addDay()->startOfDay());

    $diffInMinutes += $step->diffInMinutes($nextStep);
    $step = $nextStep;
}

echo $diffInMinutes;
使用碳\CarbonImmutable;
$created=CarbonImmutable::parse(“2021-04-11 00:07:13”);
$firstResponse=CarbonImmutable::parse(“2021-04-12 12:35:04”);
$diffInMinutes=0;
$step=$created;
while($step<$firstResponse){
如果($step->isWeekend()){
$step=$step->next(“星期一”);
继续;
}
$nextStep=min($firstResponse,$step->addDay()->startOfDay());
$diffInMinutes+=$step->diffInMinutes($nextStep);
$step=$nextStep;
}
回声$diffin分钟;

注意:警告,如果使用
Carbon
而不是
CarbonImmutable
您将需要替换
$step=$created$step=$created->toImmutable()进行编码>

你是向导吗?;)我维护
Carbon
库,我想这会有帮助^^^你是个向导吗?;)我维护
Carbon
库,我想这会有所帮助^^