木质/时间

提供时间相关功能的框架。

dev-master 2022-07-04 08:17 UTC

This package is auto-updated.

Last update: 2024-09-04 13:25:00 UTC


README

提供时间相关功能的框架。

安装

安装此库的推荐方式是通过 composer

composer require xylemical/time

用法

该框架提供时钟、微时钟、当前时间和定时器。

时钟

时钟是以秒为单位的命名固定时间点。

用法

use Xylemical\Time\Clock;

$clock = new Clock('name'); // Defaults to current time.
$clock->setTimestamp(strtotime('+1 month')); // Changes the timestamp to one month from now.

$clock = new Clock('name', strtotime('+1 day')); // Clock has timestamp for +1 day.

微时钟

微时钟是以微秒为单位的命名固定时间点。

用法

use Xylemical\Time\MicroClock;

$clock = new MicroClock('name'); // Defaults to current microtime.
$clock->setTime(microtime(TRUE)); // Changes the time to the current microtime.

$clock = new MicroClock('name', microtime(TRUE)); // Clock has current microtime.

定时器

定时器是使用微时间的命名秒表。

用法

use Xylemical\Time\Timer;

$timer = new Timer('name'); // Timers are not started by default.
$timer->start();            // Starts the timer.
$timer->stop();             // Stops the timer.

echo $timer->getTime();         // Current the time as microtime.
echo $timer->getSeconds();      // Get the seconds for the timer.
echo $timer->getMicroseconds(); // Get the microseconds for the timer.


$timer->reset(); // R

$clock = new MicroClock('name', microtime(TRUE)); // Clock has current microtime.

许可

MIT,见 LICENSE。