Skip to content

Core\Time\Instant

One exact point in time, the same everywhere in the world. It has no time zone and no calendar. Core\Time::now, Core\Time\Instant::fromEpoch and Core\Time\Instant::fromIso return one. plus, minus and since do exact arithmetic with a Duration, and in shows the instant on a zone's calendar.

An Instant is a point on the timeline. It has no calendar and no zone. Instant::fromIso reads an RFC 3339 timestamp such as 2024-03-01T12:00:00Z. Instant::fromEpoch builds one from seconds since 1 January 1970. Core\Time::now() returns the current instant.

An Instant has an epoch count and a text form in UTC. ->in($zone) gives its date and time of day in a zone, as a DateTime. It moves only by an exact Duration: plus(36h) is always thirty-six hours. since returns the exact time between two instants. A step in days or months is taken on the DateTime that ->in($zone) returns. compareTo orders two instants. The <, > and <=> operators do not compile on an Instant.

<?nvs
var $start = Core\Time\Instant::fromIso('2024-03-01T12:00:00Z');
echo $start->toIso(), "\n";
echo $start->toEpochSeconds(), "\n";
echo $start->toEpochMillis(), "\n";
var $end = $start->plus(36h);
echo $end->toIso(), "\n";
echo $end->since($start), "\n";
echo $start->minus(30m)->toIso(), "\n";
echo $start->compareTo($end), "\n";
echo $start->in('Asia/Tokyo')->format('yyyy-MM-dd HH:mm'), "\n";
echo Core\Time\Instant::fromEpoch(1709294400, { nanoseconds: 500000000 })->toIso(), "\n";
Output
2024-03-01T12:00:00Z
1709294400
1709294400000
2024-03-03T00:00:00Z
1d12h
2024-03-01T11:30:00Z
-1
2024-03-01 21:00
2024-03-01T12:00:00.5Z

Returned by

You get a Core\Time\Instant from these methods:

Members

11 members.

MemberSignature
fromEpochfromEpoch(int $seconds, { nanoseconds?: uint }): Core\Time\Instant
fromIsofromIso(string $text): Core\Time\Instant
inin(Core\Time\Zone $zone): Core\Time\DateTime
toEpochSecondstoEpochSeconds(): int
toEpochMillistoEpochMillis(): int
toEpochMicrostoEpochMicros(): int
plusplus(Core\Time\Duration $d): Core\Time\Instant
minusminus(Core\Time\Duration $d): Core\Time\Instant
sincesince(Core\Time\Instant $earlier): Core\Time\Duration
compareTocompareTo(Core\Time\Instant $other): int
toIsotoIso(): string