PHP 8.4.22 Released!

DateTime::createFromTimestamp

(PHP 8 >= 8.4.0)

DateTime::createFromTimestampCreates an instance from a Unix timestamp

Descripción

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

Creates an instance from a Unix timestamp.

Parámetros

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

Valores devueltos

Returns a new DateTime instance.

Errores/Excepciones

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

Ejemplos

Ejemplo #1 DateTime::createFromTimestamp() example

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

El ejemplo anterior mostrará:

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

User Contributed Notes

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