Time\Duration::multiplyBy

(PHP 8 >= 8.6.0)

Time\Duration::multiplyBy — Multiplies the duration by an integer factor

Descrizione

public function Time\Duration::multiplyBy(int $factor): Time\Duration

Returns a duration that is factor times as long as this duration. The sign of the duration is preserved.

Elenco dei parametri

factor

The factor to multiply by. Must be greater than or equal to 0; a factor of 0 results in a duration of zero.

Valori restituiti

Returns a new Time\Duration object.

Errori/Eccezioni

Esempi

Example #1 Time\Duration::multiplyBy() example

<?php
var_dump(\Time\Duration::fromMilliseconds(1500)->multiplyBy(4));

try {
    \Time\Duration::fromHours(1)->multiplyBy(3_000_000);
} catch (\Time\TimeException $e) {
    echo $e->getMessage(), PHP_EOL;
}

Il precedente esempio visualizzerà:

object(Time\Duration)#2 (3) {
  ["seconds"]=>
  int(6)
  ["nanoseconds"]=>
  int(0)
  ["negative"]=>
  bool(false)
}
The maximum representable range is 9_223_372_035 seconds (roughly 292 years)

Vedere anche:

+add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top