PHP 8.4.22 Released!

DateTimeImmutable::createFromTimestamp

(PHP 8 >= 8.4.0)

DateTimeImmutable::createFromTimestampCreates an instance from a Unix timestamp

説明

public static function DateTimeImmutable::createFromTimestamp(int|float $timestamp): static

Creates an instance from a Unix timestamp.

パラメータ

timestamp
Unix timestamp representing the date. A float value is also accepted which allows for microsecond precision.

戻り値

Returns a new DateTimeImmutable instance.

エラー / 例外

If the timestamp is outside the range [PHP_INT_MIN, PHP_INT_MAX], a DateRangeError is thrown.

例1 DateTimeImmutable::createFromTimestamp() example

<?php
$date
= DateTimeImmutable::createFromTimestamp(123.456789);
echo
$date->format('Y-m-d H:i:s.u');
?>

上の例の出力は以下となります。

1970-01-01 00:02:03.456789
add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top