PHP 8.4.22 Released!

DateTime::createFromTimestamp

(PHP 8 >= 8.4.0)

DateTime::createFromTimestampCreates an instance from a Unix timestamp

说明

public static function DateTime::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 DateTime instance.

错误/异常

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

示例

示例 #1 DateTime::createFromTimestamp() example

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

以上示例会输出:

1970-01-01 00:02:03.456789
添加备注

用户贡献的备注

此页面尚无用户贡献的备注。
To Top