赵伟-克鲁什 / 持续时间
GoLang time.Duration 的 PHP 实现
v1.0.0
2020-09-29 08:52 UTC
This package is auto-updated.
Last update: 2024-09-29 05:42:54 UTC
README
GoLang's time.Duration 的 PHP 实现
代码主要移植自 GoLang 源代码。请参阅 time/format.go 和 time/time.go
设置
确保已安装 composer,然后运行以下命令
composer require pavel-krush/duration
这将在您的 vendor 文件夹中获取库。然后您可以将以下内容添加到您的 .php 文件中,以使用该库
require_once __DIR__.'/vendor/autoload.php';
用法
要解析包含持续时间的字符串,请使用 Parser 类
$d = \PavelKrush\Duration\Parser::fromString("13h10m21s"); print $d->Hours() . "\n"; // 13.345 print $d->Minutes() . "\n"; // 790.7 print $d->Seconds() . "\n"; // 47421 print $d->Round(new \PavelKrush\Duration\Duration(\PavelKrush\Duration\Duration::Minute)); // 13h10m0s