wallacemaxters / timer
2.2.1
2016-06-21 19:42 UTC
Requires
- php: >=5.4.0
- phplegends/collections: 1.*
Requires (Dev)
- victorjonsson/markdowndocs: 1.2.*
README
#WallaceMaxters\Timer 库
这是一个仅用于 PHP 中的时间处理的库。
有时我们需要处理小时,超过 PHP 中的 24 小时,但 DateTime 类或其他日期函数没有令人满意的解决方案;
因此开发了 Timer 库。
使用它,您可以非常简单地进行时间操作
use WallaceMaxters\Timer\Time; $time = Time::create(0, 0, 10); $time->format('%h:%i%s'); // '00:00:10' $time->addSeconds(30); $time->format(); // '00:00:40' $time->addSeconds(-50); $time->format('%h:%i%s'); // '-00:00:10'
如果需要,您也可以使用 Collection 类,以方便对时间进行一些操作。
use WallaceMaxters\Timer\Collection; $collection = new Collection; $collection[] = Time::create(0, 10, 0); $collection[] = Time::createFromString('10 seconds'); $collection[] = Time::createFromFormat('%h:%i', '00:50'); $collection->sum(); // new Time(0, 11, 0); $collection->min(); // new time(0, 0, 10);
超过 24 小时时间的示例
// DateTime $date = DateTime::createFromFormat('25:00:00'); var_dump($date->format('H:i:s')); // 01:00:00 // WallaceMaxters\Timer\Timer $time = Time::createFromFormat('%h:%i:%s', '26:00:00'); var_dump($time->format()); // '26:00:00'