Skip to content

Latest commit

 

History

History
58 lines (37 loc) · 958 Bytes

README.md

File metadata and controls

58 lines (37 loc) · 958 Bytes

Clock

Implementation of the PSR-20 Clock Interface.

Installation

Install via Composer:

$ composer require sergeyakovlev/clock

Usage

System 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');

Frozen Clock

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

Links