Implementation of the PSR-20 Clock Interface.
Install via Composer:
$ composer require sergeyakovlev/clock
The current time with default time zone:
use SergeYakovlev\Clock\SystemClock;
$clock = new SystemClock();
echo $clock->now()->format('c');
The current time with the specified time zone:
use DateTimeZone;
use SergeYakovlev\Clock\SystemClock;
$clock = new SystemClock(
new DateTimeZone('UTC')
);
echo $clock->now()->format('c');
The specified time:
use DateTimeImmutable;
use SergeYakovlev\Clock\FrozenClock;
$clock = new FrozenClock(
new DateTimeImmutable('2001-02-03T04:05:06+07:00')
);
echo $clock->now()->format('c'); // 2001-02-03T04:05:06+07:00
- PHP-FIG.org: PSR-20 Clock
- GitHub: PSR Clock