Time\Duration::fromMinutes
(PHP 8 >= 8.6.0)
Time\Duration::fromMinutes — Creates a duration from a number of minutes
Description
Creates a non-negative duration of minutes minutes.
The value is normalized into whole seconds and nanoseconds, see the
Time\Duration::$seconds and
Time\Duration::$nanoseconds properties.
Parameters
minutes
The number of minutes.
Must be greater than or equal to 0.
Return Values
Returns a new Time\Duration object.
Errors/Exceptions
-
If
minutesis negative, a ValueError is thrown. -
If the resulting duration exceeds the maximum length of a duration, a Time\TimeException is thrown.
Examples
Example #1 Time\Duration::fromMinutes() example
<?php
var_dump(\Time\Duration::fromMinutes(90));
try {
\Time\Duration::fromMinutes(-1);
} catch (ValueError $e) {
echo $e->getMessage(), PHP_EOL;
}The above example will output:
object(Time\Duration)#1 (3) {
["seconds"]=>
int(5400)
["nanoseconds"]=>
int(0)
["negative"]=>
bool(false)
}
Time\Duration::fromMinutes(): Argument #1 ($minutes) must be greater than or equal to 0
See Also
- Time\Duration::fromSeconds() - Creates a duration from a number of seconds and nanoseconds
- Time\Duration::fromHours() - Creates a duration from a number of hours
- Time\Duration::fromIso8601DurationString() - Creates a duration from an ISO 8601 duration string
来源:PHP Documentation Group · 作者与贡献记录 · CC BY 3.0。离线整理了版式、链接和媒体显示。
