bitandblack/duration

以面向对象的方式处理持续时间。

支持包维护!
赞助我

1.1.0 2024-02-02 12:26 UTC

This package is auto-updated.

Last update: 2024-08-31 00:30:06 UTC


README

PHP from Packagist Codacy Badge Latest Stable Version Total Downloads License

Bit&Black Duration

以面向对象的方式处理持续时间。

安装

此库是为与 Composer 一起使用而制作的。通过运行 composer require bitandblack/duration 将其添加到您的项目中。

用法

创建一个新的实例如下

<?php

use BitAndBlack\Duration\Duration;

$duration = Duration::createFromDays(7);

您可以使用

  • createFromNanoSeconds 从纳秒创建持续时间。
  • createFromMicroSeconds 从微秒创建持续时间。
  • createFromMilliSeconds 从毫秒创建持续时间。
  • createFromSeconds 从秒创建持续时间。
  • createFromMinutes 从分钟创建持续时间。
  • createFromHours 从小时创建持续时间。
  • createFromDays 从天创建持续时间。
  • createFromWeeks 从周创建持续时间。

获取其他单位的持续时间

<?php

// This will result in `604800.0`.
$seconds = $duration->getSeconds();

您可以使用

  • getNanoSeconds 获取纳秒表示的持续时间。
  • getMicroSeconds 获取微秒表示的持续时间。
  • getMilliSeconds 获取毫秒表示的持续时间。
  • getSeconds 获取秒表示的持续时间。
  • getMinutes 获取分钟表示的持续时间。
  • getHours 获取小时表示的持续时间。
  • getDays 获取天表示的持续时间。
  • getWeeks 获取周表示的持续时间。

帮助

如果您有任何问题,请随时通过 hello@bitandblack.com 联系我们。

有关Bit&Black的更多信息可以在 www.bitandblack.com 找到。